PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | app/ApiRouter.php +19 -60 0.11.13.2.1 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * API router
4 5 */
5 6
@@ -4,55 +5,24 @@
4 5 */
5 6
6 7 namespace Extendify;
7 8
8 -use Extendify\Config;
9 -use Extendify\Http;
9 +defined('ABSPATH') || die('No direct access.');
10 10
11 11 /**
12 12 * Simple router for the REST Endpoints
13 13 */
14 +
14 15 class ApiRouter extends \WP_REST_Controller
15 16 {
16 -
17 17 /**
18 18 * The class instance.
19 19 *
20 - * @var $instance
20 + * @var self|null
21 21 */
22 22 protected static $instance = null;
23 23
24 24 /**
25 - * The capability required for access.
26 - *
27 - * @var $capability
28 - */
29 - protected $capability;
30 -
31 -
32 - /**
33 - * The constructor
34 - */
35 - public function __construct()
36 - {
37 - $this->capability = Config::$requiredCapability;
38 - add_filter(
39 - 'rest_request_before_callbacks',
40 - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
41 - function ($response, $handler, $request) {
42 - // Add the request to our helper class.
43 - if ($request->get_header('x_extendify')) {
44 - Http::init($request);
45 - }
46 -
47 - return $response;
48 - },
49 - 10,
50 - 3
51 - );
52 - }
53 -
54 - /**
55 25 * Check the authorization of the request
56 26 *
57 27 * @return boolean
58 28 */
@@ -58,10 +28,13 @@
58 28 */
59 29 public function checkPermission()
60 30 {
61 31 // Check for the nonce on the server (used by WP REST).
62 - if (isset($_SERVER['HTTP_X_WP_NONCE']) && \wp_verify_nonce(sanitize_text_field(wp_unslash($_SERVER['HTTP_X_WP_NONCE'])), 'wp_rest')) {
63 - return \current_user_can($this->capability);
32 + if (
33 + isset($_SERVER['HTTP_X_WP_NONCE'])
34 + && \wp_verify_nonce(sanitize_text_field(wp_unslash($_SERVER['HTTP_X_WP_NONCE'])), 'wp_rest')
35 + ) {
36 + return \current_user_can(Config::$requiredCapability);
64 37 }
65 38
66 39 return false;
67 40 }
@@ -76,20 +49,13 @@
76 49 * @return void
77 50 */
78 51 public function getHandler($namespace, $endpoint, $callback)
79 52 {
80 - \register_rest_route(
81 - $namespace,
82 - $endpoint,
83 - [
84 - 'methods' => 'GET',
85 - 'callback' => $callback,
86 - 'permission_callback' => [
87 - $this,
88 - 'checkPermission',
89 - ],
90 - ]
91 - );
53 + \register_rest_route($namespace, $endpoint, [
54 + 'methods' => 'GET',
55 + 'callback' => $callback,
56 + 'permission_callback' => [$this, 'checkPermission'],
57 + ]);
92 58 }
93 59
94 60 /**
95 61 * The post handler
@@ -101,20 +67,13 @@
101 67 * @return void
102 68 */
103 69 public function postHandler($namespace, $endpoint, $callback)
104 70 {
105 - \register_rest_route(
106 - $namespace,
107 - $endpoint,
108 - [
109 - 'methods' => 'POST',
110 - 'callback' => $callback,
111 - 'permission_callback' => [
112 - $this,
113 - 'checkPermission',
114 - ],
115 - ]
116 - );
71 + \register_rest_route($namespace, $endpoint, [
72 + 'methods' => 'POST',
73 + 'callback' => $callback,
74 + 'permission_callback' => [$this, 'checkPermission'],
75 + ]);
117 76 }
118 77
119 78 /**
120 79 * The caller