PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.4
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.4
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-rank.php

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

106 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Revoke Rank Ability
4 *
5 * @package GamiPress\AI_Assistant\Ability\Revoke_Rank
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_Rank extends GamiPress_AI_Assistant_Ability {
13
14 public $ability = 'revoke-rank';
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 a rank in GamiPress', 'gamipress' ),
25 'description' => __( 'Revokes a specific rank to a user. Requires the user, the rank type, and the rank 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 'rank_type' => array(
34 'description' => __( 'The GamiPress rank type.', 'gamipress' ),
35 'type' => 'string',
36 //'enum' => gamipress_get_rank_types_slugs(),
37 ),
38 'rank' => array(
39 'description' => __( 'The rank to award. Get the rank ID.', 'gamipress' ),
40 'type' => 'string',
41 ),
42 ),
43 'required' => array( 'user', 'rank_type', 'rank' ),
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 'rank_type' => '',
64 'rank' => '',
65 ) );
66
67 $user_search = sanitize_text_field( $args['user'] );
68 $rank_type = sanitize_text_field( $args['rank_type'] );
69 $rank_search = sanitize_text_field( $args['rank'] );
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 ranks type
76 $type = gamipress_get_rank_type( $rank_type );
77 if( ! $type )
78 return $this->response_error( sprintf( __( 'I couldn\'t find the rank type "%s".', 'gamipress' ), $rank_type ) );
79
80 // Check the post
81 $rank = $this->get_post( $rank_search, array( 'post_type' => $type['slug'] ) );
82 if( $this->is_response_error( $rank ) ) return $rank;
83
84 // Revoke the rank from the user
85 gamipress_revoke_rank_to_user( $user->ID, $rank->ID );
86
87 $user_display = $user->display_name;
88
89 if ( current_user_can( 'edit_users' ) ) {
90 $user_display = '[' . $user_display . '](' . get_edit_user_link( $user->ID ) . ')';
91 }
92
93 $post_display = $rank->post_title;
94
95 if ( current_user_can( 'edit_post', $rank->ID ) ) {
96 $post_display = '[' . $rank->post_title . '](' . get_edit_post_link( $rank->ID ) . ')';
97 }
98
99 $message = sprintf( __( 'I revoked %s to %s.', 'gamipress' ), $post_display, $user_display );
100
101 return $this->response_success( $message );
102
103 }
104
105 }
106 new GamiPress_AI_Assistant_Ability_Revoke_Rank();