PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.3
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.3
8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 7.8.6 All 45 releases
gamipress / modules / ai-assistant / includes / abilities / add-points-deducts.php

add-points-deducts.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 8.0.3, at modules/ai-assistant/includes/abilities/add-points-deducts.php

103 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add Points Deducts Ability
4 *
5 * @package GamiPress\AI_Assistant\Ability\Add_Points_Deducts
6 * @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 class GamiPress_AI_Assistant_Ability_Add_Points_Deducts extends GamiPress_AI_Assistant_Ability {
13
14 public $ability = 'add-points-deducts';
15
16 /**
17 * Register the ability
18 *
19 * @since 1.0.0
20 */
21 public function register() {
22
23 $this->args = array(
24 'label' => esc_html__( 'Add points deducts to a points type in GamiPress', 'gamipress' ),
25 'description' => esc_html__( 'Design and insert a new points deduct into the database.', 'gamipress' ),
26 'input_schema' => array(
27 'type' => 'object',
28 'properties' => array(
29 'points_type' => array(
30 'description' => __( 'The GamiPress points type.', 'gamipress' ),
31 'type' => 'string',
32 //'enum' => gamipress_get_points_types_slugs(),
33 ),
34 'points_deducts' => array(
35 'description' => esc_html__( 'List of points deducts or rules for the points type. Define the criteria to meet to earn points of this type.', 'gamipress' ),
36 'type' => 'array',
37 'items' => array(
38 'type' => 'object',
39 'properties' => gamipress_ai_assistant_get_requirements_properties( 'points-deduct' ),
40 ),
41 ),
42 ),
43 'required' => array( 'points_type' ),
44 'additionalProperties' => false,
45 ),
46 );
47
48 }
49
50 /**
51 * Ability execute callback
52 *
53 * @since 1.0.0
54 *
55 * @param array $args
56 *
57 * @return array array( 'success' => true|false, 'message' => '' )
58 */
59 public function execute( $args ) {
60
61 $args = wp_parse_args( (array) $args, array(
62 'points_type' => '',
63 'points_deducts' => array(),
64 ) );
65
66 $points_type = sanitize_text_field( $args['points_type'] );
67 $points_deducts = $args['points_deducts'];
68
69 // Check the points type
70 $type = gamipress_get_points_type( $points_type );
71
72 if( ! $type )
73 return $this->response_error( sprintf( __( 'I couldn\'t find the points type "%s".', 'gamipress' ), $points_type ) );
74
75 // Requirements
76 $updated_deducts = gamipress_ai_assistant_process_requirements(
77 $points_deducts,
78 $type['ID'],
79 'points-deduct'
80 );
81
82 $deducts_count = count( $updated_deducts );
83 $deducts_label = _n( 'deduct', 'deducts', $deducts_count, 'gamipress' );
84 $deducts_answer = gamipress_ai_assistant_get_requirements_answer( $updated_deducts );
85
86 // Final response
87 $post_link = get_edit_post_link( $type['ID'] );
88 $post_display = $type['plural_name'];
89
90 if( $post_link !== null ) {
91 $post_display = '[' . $post_display . '](' . $post_link . ')';
92 }
93
94 // translators: %1$s: Deduct label. %2$s: Point type name
95 $message = sprintf( __( 'I added the following points %1$s to %2$s:', 'gamipress' ), $deducts_label, $post_display );
96 $message .= $deducts_answer;
97
98 return $this->response_success( $message );
99
100 }
101
102 }
103 new GamiPress_AI_Assistant_Ability_Add_Points_Deducts();