PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.4
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.4
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/API/API.php +35 -1 3.0.73.4.4 View file →
@@ -124,12 +124,30 @@
124 124 * @param $request WP_REST_Request for getting all route request in time.
125 125 *
126 126 * @return WP_Error|boolean
127 127 */
128 + public function _permission_check( WP_REST_Request $request ) {
129 + $this->request = $request;
130 + $this->api_key = $this->utils('options')->get( 'api_key' );
131 + if(!current_user_can('delete_posts')){
132 + return false;
133 + }
134 +
135 + add_filter('wp_redirect', '__return_false', 999);
136 +
137 + return $this->permission_check( $request );
138 + }
139 +
140 + /**
141 + * @param $request WP_REST_Request for getting all route request in time.
142 + *
143 + * @return WP_Error|boolean
144 + */
128 145 public function permission_check( WP_REST_Request $request ) {
129 146 $this->request = $request;
130 147 $this->api_key = $this->utils('options')->get( 'api_key' );
131 148
149 +
132 150 if ( ! empty( $this->api_key ) ) {
133 151 return true;
134 152 }
135 153
@@ -184,9 +202,9 @@
184 202 $endpoint,
185 203 [
186 204 'methods' => $methods,
187 205 'callback' => $callback,
188 - 'permission_callback' => [ $this, 'permission_check' ],
206 + 'permission_callback' => [ $this, '_permission_check' ],
189 207 'args' => $args,
190 208 ]
191 209 );
192 210 }
@@ -211,8 +229,24 @@
211 229 * @return WP_REST_Response
212 230 */
213 231 public function success( $data ) {
214 232 return new WP_REST_Response( $data, 200 );
233 + }
234 +
235 + /**
236 + * Enhanced success response wrapper that automatically adds success flag and wraps data
237 + *
238 + * @param $data mixed The data to be wrapped in the response
239 + *
240 + * @return WP_REST_Response
241 + */
242 + public function successWithData( $data ) {
243 + $enhanced_response = [
244 + 'success' => true,
245 + 'data' => $data
246 + ];
247 +
248 + return $this->success( $enhanced_response );
215 249 }
216 250 /**
217 251 * @param $error_code string
218 252 * @param $error_message string|array