PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.5
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.5
8.0.5 8.0.4 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 All 47 releases
gamipress / modules / ai-assistant / includes / abilities / revoke-achievement.php

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

107 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Revoke Achievement Ability
4 *
5 * @package GamiPress\AI_Assistant\Ability\Revoke_Achievement
6 * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 class GamiPress_AI_Assistant_Ability_Revoke_Achievement extends GamiPress_AI_Assistant_Ability {
13
14 public $ability = 'revoke-achievement';
15
16 /**
17 * Register the ability
18 *
19 * @since 1.0.0
20 */
21 public function register() {
22
23 $this->args = array(
24 'label' => __( 'Revoke an achievement in GamiPress', 'gamipress' ),
25 'description' => __( 'Revokes a specific achievement to a user. Requires the user, the achievement type, and the achievement to award.', 'gamipress' ),
26 'input_schema' => array(
27 'type' => 'object',
28 'properties' => array(
29 'user' => array(
30 'type' => 'string',
31 'description' => __( 'The ID, email or name of the user who will receive the points.', 'gamipress' ),
32 ),
33 'achievement_type' => array(
34 'description' => __( 'The GamiPress achievement type.', 'gamipress' ),
35 'type' => 'string',
36 //'enum' => gamipress_get_achievement_types_slugs(),
37 ),
38 'achievement' => array(
39 'description' => __( 'The achievement to award. Get the achievement ID.', 'gamipress' ),
40 'type' => 'string',
41 ),
42 ),
43 'required' => array( 'user', 'achievement_type', 'achievement' ),
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 'user' => '',
63 'achievement_type' => '',
64 'achievement' => '',
65 ) );
66
67 $user_search = sanitize_text_field( $args['user'] );
68 $achievement_type = sanitize_text_field( $args['achievement_type'] );
69 $achievement_search = sanitize_text_field( $args['achievement'] );
70
71 // Check the user
72 $user = $this->get_user( $user_search );
73 if( $this->is_response_error( $user ) ) return $user;
74
75 // Check the achievements type
76 $type = gamipress_get_achievement_type( $achievement_type );
77 if( ! $type )
78 return $this->response_error( sprintf( __( 'I couldn\'t find the achievement type "%s".', 'gamipress' ), $achievement_type ) );
79
80 // Check the post
81 $achievement = $this->get_post( $achievement_search, array( 'post_type' => $type['slug'] ) );
82
83 if( $this->is_response_error( $achievement ) ) return $achievement;
84
85 // Revoke the achievement to the user
86 gamipress_revoke_achievement_to_user( $achievement->ID, $user->ID );
87
88 $user_display = $user->display_name;
89
90 if ( current_user_can( 'edit_users' ) ) {
91 $user_display = '[' . $user_display . '](' . get_edit_user_link( $user->ID ) . ')';
92 }
93
94 $post_display = $achievement->post_title;
95
96 if ( current_user_can( 'edit_post', $achievement->ID ) ) {
97 $post_display = '[' . $achievement->post_title . '](' . get_edit_post_link( $achievement->ID ) . ')';
98 }
99
100 $message = sprintf( __( 'I revoked %s to %s.', 'gamipress' ), $post_display, $user_display );
101
102 return $this->response_success( $message );
103
104 }
105
106 }
107 new GamiPress_AI_Assistant_Ability_Revoke_Achievement();