PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.8
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.8
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / rest-api / class-wpsc-rest-current-user.php

class-wpsc-rest-current-user.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.3.8, at includes/rest-api/class-wpsc-rest-current-user.php

66 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_REST_Current_User' ) ) :
7
8 final class WPSC_REST_Current_User {
9
10 /**
11 * Initialize this class
12 *
13 * @return void
14 */
15 public static function init() {
16
17 add_action( 'wpsc_rest_register_routes', array( __CLASS__, 'register_routes' ) );
18 }
19
20 /**
21 * Register routes
22 *
23 * @return void
24 */
25 public static function register_routes() {
26
27 register_rest_route(
28 'supportcandy/v2',
29 '/current-user',
30 array(
31 'methods' => 'GET',
32 'callback' => array( __CLASS__, 'get_current_user' ),
33 'permission_callback' => 'is_user_logged_in',
34 ),
35 );
36 }
37
38 /**
39 * Current user information
40 *
41 * @param WP_REST_Request $request - request object.
42 * @return WP_Error|WP_REST_Response
43 */
44 public static function get_current_user( $request ) {
45
46 $current_user = WPSC_Current_User::$current_user;
47
48 $data = array(
49 'name' => $current_user->customer->name,
50 'email' => $current_user->customer->email,
51 'is_agent' => $current_user->is_agent,
52 );
53
54 if ( $current_user->is_agent ) {
55
56 $agent_roles = get_option( 'wpsc-agent-roles', array() );
57 $data['agent_caps'] = $agent_roles[ $current_user->agent->role ]['caps'];
58 }
59
60 return new WP_REST_Response( $data, 200 );
61 }
62 }
63 endif;
64
65 WPSC_REST_Current_User::init();
66