mirror of
https://git.sindominio.net/estibadores/wordpress.git
synced 2024-11-14 23:21:07 +01:00
79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* @apiDefine 401Error
|
||
|
*
|
||
|
* @apiError (Error 401) rest_forbidden You are not authorized to access this API endpoint
|
||
|
* @apiErrorExample {json} 401 Error Response:
|
||
|
* HTTP/1.1 401 Bad Request
|
||
|
* {
|
||
|
* "code": "rest_forbidden",
|
||
|
* "message": "Sorry, you are not allowed to do that."
|
||
|
* }
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @apiDefine 404Error
|
||
|
*
|
||
|
* @apiError (Error 404) rest_no_route Endpoint not found
|
||
|
* @apiErrorExample {json} 404 Error Response:
|
||
|
* HTTP/1.1 404 Not Found
|
||
|
* {
|
||
|
* "code": "rest_no_route",
|
||
|
* "message": "No route was found matching the URL and request method"
|
||
|
* }
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @apiDefine 400Error
|
||
|
*
|
||
|
* @apiError rest_forbidden You are not authorized to access this API endpoint
|
||
|
* @apiErrorExample {json} 400 Error Response:
|
||
|
* HTTP/1.1 400 Bad Request
|
||
|
* {
|
||
|
* "error": "invalid",
|
||
|
* "message": "Invalid request"
|
||
|
* }
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @apiDefine 400MissingError
|
||
|
* @apiError (Error 400) rest_missing_callback_param Some required parameters are not present or not in the correct format
|
||
|
* @apiErrorExample {json} 400 Error Response:
|
||
|
* HTTP/1.1 400 Bad Request
|
||
|
* {
|
||
|
* "code": "rest_missing_callback_param",
|
||
|
* "message": "Missing parameter(s): PARAM"
|
||
|
* }
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Base class for Search Regex API endpoints
|
||
|
*/
|
||
|
class Search_Regex_Api_Route {
|
||
|
/**
|
||
|
* Checks a capability
|
||
|
*
|
||
|
* @param WP_REST_Request $request Request.
|
||
|
* @return Bool
|
||
|
*/
|
||
|
public function permission_callback( WP_REST_Request $request ) {
|
||
|
return Search_Regex_Capabilities::has_access( Search_Regex_Capabilities::CAP_SEARCHREGEX_SEARCH );
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get route details
|
||
|
*
|
||
|
* @param String $method Method name.
|
||
|
* @param String $callback Function name.
|
||
|
* @param callable|Bool $permissions Permissions callback.
|
||
|
* @return Array
|
||
|
*/
|
||
|
public function get_route( $method, $callback, $permissions = false ) {
|
||
|
return [
|
||
|
'methods' => $method,
|
||
|
'callback' => [ $this, $callback ],
|
||
|
'permission_callback' => $permissions ? $permissions : [ $this, 'permission_callback' ],
|
||
|
];
|
||
|
}
|
||
|
}
|