PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / trunk
Advanced Access Manager – Access Governance for WordPress vtrunk
6.8.4 6.8.5 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13 6.9.14 6.9.15 6.9.16 6.9.17 6.9.18 6.9.19 6.9.2 6.9.20 6.9.21 6.9.22 6.9.23 6.9.24 6.9.25 6.9.26 6.9.27 6.9.28 6.9.29 6.9.3 6.9.30 6.9.31 6.9.32 6.9.33 6.9.34 6.9.35 6.9.36 6.9.37 6.9.38 6.9.39 6.9.4 6.9.41 6.9.42 6.9.43 6.9.44 6.9.45 6.9.46 6.9.47 6.9.48 6.9.49 6.9.5 6.9.51 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.0-alpha.6 7.0.0-alpha.7 7.0.0-beta.1 7.0.0-rc1 7.0.0-rc2 7.0.0-rc3 7.0.1 7.0.10 7.0.11 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7 7.0.8 7.0.9 7.1.0 7.1.1 trunk 3.0 4.0 4.0.1 4.1 4.2 4.3 4.4 4.4.1 4.5 4.6 4.6.1 4.6.2 4.7 4.7.1 4.7.2 4.7.5 4.7.6 4.8 4.8.1 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.5.1 4.9.5.2 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1 5.1.1 5.10 5.11 5.2 5.2.1 5.2.5 5.2.6 5.2.7 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.4 5.4.1 5.4.2 5.4.3 5.4.3.1 5.4.3.2 5.5 5.5.1 5.5.2 5.6 5.6.1 5.6.1.1 5.7 5.7.1 5.7.2 5.7.3 5.8 5.8.1 5.8.2 5.8.3 5.9 5.9.1 5.9.1.1 5.9.2 5.9.2.1 5.9.3 5.9.4 5.9.5 5.9.6 5.9.6.1 5.9.6.2 5.9.6.3 5.9.7 5.9.7.1 5.9.7.2 5.9.7.3 5.9.8 5.9.8.1 5.9.9 5.9.9.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.2.0 6.2.1 6.2.2 6.3.0 6.3.1 6.3.2 6.3.3 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.6.0 6.6.1 6.6.2 6.6.3 6.6.4 6.7.0 6.7.1 6.7.2 6.7.3 6.7.4 6.7.5 6.7.6 6.7.7 6.7.8 6.7.9 6.8.0 6.8.1 6.8.2 6.8.3
advanced-access-manager / application / Restful / Mu.php
advanced-access-manager / application / Restful Last commit date
AccessDeniedRedirect.php 1 year ago AdminToolbar.php 1 year ago ApiRoute.php 1 year ago BackendMenu.php 1 year ago BackwardCompatibility.php 1 year ago Capability.php 1 year ago Configs.php 5 months ago Content.php 1 year ago Identity.php 1 year ago Jwt.php 5 months ago LoginRedirect.php 1 year ago LogoutRedirect.php 1 year ago Metabox.php 1 year ago Mu.php 1 year ago NotFoundRedirect.php 1 year ago Policies.php 1 year ago Roles.php 1 year ago SecureLogin.php 1 year ago SecurityAudit.php 1 year ago ServiceTrait.php 1 year ago Settings.php 1 year ago Urls.php 1 year ago Users.php 1 year ago Widgets.php 1 year ago
Mu.php
209 lines
1 <?php
2
3 /**
4 * ======================================================================
5 * LICENSE: This file is subject to the terms and conditions defined in *
6 * file 'license.txt', which is part of this source code package. *
7 * ======================================================================
8 */
9
10 /**
11 * RESTful API service that must be on at all time
12 *
13 * @package AAM
14 * @version 7.0.0
15 */
16 class AAM_Restful_Mu
17 {
18
19 use AAM_Restful_ServiceTrait;
20
21 /**
22 * Necessary permissions to access endpoint
23 *
24 * @version 7.0.0
25 */
26 const PERMISSIONS = [
27 'aam_manager',
28 'aam_manage_admin_toolbar'
29 ];
30
31 /**
32 * Construct
33 *
34 * @return void
35 * @access protected
36 *
37 * @version 7.0.0
38 */
39 protected function __construct()
40 {
41 // Covering the bug in WordPress core that does not set correct user local
42 add_filter('rest_pre_dispatch', function($r, $_, $request) {
43 global $wp_locale_switcher;
44
45 if (strpos($request->get_route(), '/aam/') !== false) {
46 $user_id = get_current_user_id();
47
48 if (function_exists('switch_to_user_locale')) {
49 switch_to_user_locale($user_id);
50 } elseif (is_a($wp_locale_switcher, 'WP_Locale_Switcher')) {
51 $wp_locale_switcher->switch_to_locale(
52 get_user_locale($user_id), $user_id
53 );
54 }
55 }
56
57 return $r;
58 }, 10, 3);
59
60 // Register API endpoint
61 add_action('rest_api_init', function() {
62 $permission_cb = function() {
63 return current_user_can('aam_manager')
64 && AAM::api()->misc->is_admin();
65 };
66
67 // Reset AAM
68 $this->_register_route('/core/reset', [
69 'methods' => WP_REST_Server::DELETABLE,
70 'callback' => [ $this, 'reset' ]
71 ], $permission_cb, false);
72
73 // Export AAM settings, configurations & roles
74 $this->_register_route('/core/export', [
75 'methods' => WP_REST_Server::READABLE,
76 'callback' => [ $this, 'export' ]
77 ], $permission_cb, false);
78
79 // Import AAM settings, configurations & roles
80 $this->_register_route('/core/import', [
81 'methods' => WP_REST_Server::EDITABLE,
82 'callback' => [ $this, 'import' ]
83 ], $permission_cb, false);
84 });
85
86 // Get currently managed "Access Level"
87 add_filter(
88 'aam_rest_get_access_level_filter',
89 [ $this, 'get_access_level' ],
90 10,
91 2
92 );
93
94 // Handle common REST errors
95 add_filter(
96 'aam_rest_get_error_response_filter',
97 [ $this, 'get_error_response' ],
98 10,
99 4
100 );
101
102 // Register a common AAM, access level aware RESTful API endpoint
103 add_action(
104 'aam_rest_register_route',
105 function($route, $args, $auth, $access_level_aware = true, $ns = null) {
106 return $this->_register_route(
107 $route,
108 $args,
109 $auth,
110 $access_level_aware,
111 $ns
112 );
113 }, 10, 5
114 );
115 }
116
117 /**
118 * Reset all AAM settings
119 *
120 * @return void
121 * @access public
122 *
123 * @version 7.0.0
124 */
125 public function reset()
126 {
127 return rest_ensure_response([
128 'success' => AAM_Service_Core::get_instance()->reset()
129 ]);
130 }
131
132 /**
133 * Export all AAM settings
134 *
135 * @return void
136 * @access public
137 *
138 * @version 7.0.0
139 */
140 public function export()
141 {
142 return rest_ensure_response(AAM_Service_Core::get_instance()->export());
143 }
144
145 /**
146 * Export all AAM settings
147 *
148 * @param WP_REST_Request $request
149 *
150 * @return void
151 * @access public
152 *
153 * @version 7.0.0
154 */
155 public function import($request)
156 {
157 return rest_ensure_response([
158 'success' => AAM_Service_Core::get_instance()->import(
159 $request->get_param('dataset')
160 )
161 ]);
162 }
163
164 /**
165 * Get current access level
166 *
167 * @param null|object $access_level
168 * @param WP_REST_Request $request
169 *
170 * @return null|object
171 * @access public
172 *
173 * @version 7.0.0
174 */
175 public function get_access_level($access_level, $request)
176 {
177 if (is_null($access_level)) {
178 $access_level = $this->_determine_access_level($request);
179 }
180
181 return $access_level;
182 }
183
184 /**
185 * Get RESTful error response
186 *
187 * @param mixed $response
188 * @param Exception $exception
189 * @param string $rest_code
190 * @param int $http_status
191 *
192 * @return WP_REST_Response
193 * @access public
194 *
195 * @version 7.0.0
196 */
197 public function get_error_response(
198 $response, $exception, $rest_code, $http_status
199 ) {
200 if (is_null($response)) {
201 $response = $this->_prepare_error_response(
202 $exception, $rest_code, $http_status
203 );
204 }
205
206 return $response;
207 }
208
209 }