PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.3.2
Strong Testimonials v3.3.2
3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / wpchill / class-wpchill-rest-api.php
strong-testimonials / admin / wpchill Last commit date
apps 8 months ago assets 1 year ago icons 1 year ago scripts 8 months ago class-wpchill-about-us.php 1 year ago class-wpchill-notifications.php 8 months ago class-wpchill-rest-api.php 1 year ago class-wpchill-upsells.php 1 month ago
class-wpchill-rest-api.php
135 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound
8 class WPChill_Rest_Api {
9 protected $namespace = 'wpchill/v1';
10
11 public function __construct() {
12 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
13 }
14
15 public function register_routes() {
16 register_rest_route(
17 $this->namespace,
18 '/notifications',
19 array(
20 'methods' => 'GET',
21 'callback' => array( $this, 'get_notifications' ),
22 'permission_callback' => array( $this, '_permissions_check' ),
23 )
24 );
25
26 register_rest_route(
27 $this->namespace,
28 '/notifications',
29 array(
30 'methods' => 'DELETE',
31 'callback' => array( $this, 'delete_notifications' ),
32 'permission_callback' => array( $this, '_permissions_check' ),
33 )
34 );
35
36 register_rest_route(
37 $this->namespace,
38 '/notifications/(?P<id>[\w-]+)',
39 array(
40 'methods' => 'DELETE',
41 'callback' => array( $this, 'delete_notification' ),
42 'permission_callback' => array( $this, '_permissions_check' ),
43 )
44 );
45
46 register_rest_route(
47 $this->namespace,
48 '/activate-plugin',
49 array(
50 'methods' => 'POST',
51 'callback' => array( $this, 'plugin_activation' ),
52 'permission_callback' => array( $this, '_permissions_check' ),
53 )
54 );
55
56 do_action( 'wpchill_rest_api_register_routes', $this );
57 }
58
59 public function process_request( $request ) {
60 $manager = WPChill_Notifications::get_instance();
61 if ( 'DELETE' === $request->get_method() ) {
62 $body = $request->get_json_params();
63 $post_id = isset( $body['id'] ) ? $body['id'] : false;
64 if ( $post_id ) {
65 $permanent = isset( $body['permanent'] ) ? $body['permanent'] : false;
66 $manager->clear_notification( $post_id, $permanent );
67 return rest_ensure_response( true );
68 }
69 $manager->clear_notifications();
70 return rest_ensure_response( true );
71 }
72
73 $notifications = $manager->get_notifications();
74
75 $is_empty = array_reduce(
76 $notifications,
77 function ( $carry, $item ) {
78 return $carry && empty( $item );
79 },
80 true
81 );
82
83 if ( ! $is_empty ) {
84 return rest_ensure_response( $notifications );
85 }
86
87 return rest_ensure_response( array() );
88 }
89
90 public function delete_notifications() {
91 $manager = WPChill_Notifications::get_instance();
92 $manager->clear_notifications();
93 return rest_ensure_response( true );
94 }
95
96 public function delete_notification( $request ) {
97 $manager = WPChill_Notifications::get_instance();
98 $body = $request->get_json_params();
99 $notification_id = $request->get_param( 'id' );
100
101 if ( ! $notification_id ) {
102 return rest_ensure_response( false );
103 }
104
105 $permanent = isset( $body['permanent'] ) ? $body['permanent'] : false;
106 $manager->clear_notification( $notification_id, $permanent );
107 return rest_ensure_response( true );
108 }
109
110 public function get_notifications() {
111 $manager = WPChill_Notifications::get_instance();
112 $notifications = $manager->get_notifications();
113
114 $is_empty = array_reduce(
115 $notifications,
116 function ( $carry, $item ) {
117 return $carry && empty( $item );
118 },
119 true
120 );
121
122 return rest_ensure_response( $is_empty ? array() : $notifications );
123 }
124
125 public function plugin_activation( $request ) {
126 $plugin_slug = $request->get_param( 'plugin' );
127
128 return rest_ensure_response( WPChill_About_Us::activate_plugin( $plugin_slug ) );
129 }
130
131 public function _permissions_check() {
132 return current_user_can( 'manage_options' );
133 }
134 }
135