rest_pre_serve_request
Filters whether the REST API request has already been served.
Allow sending the request manually - by returning true, the API result will not be sent to the client.
Usage
add_filter( 'rest_pre_serve_request', 'wp_kama_rest_pre_serve_request_filter', 10, 4 );
/**
* Function for `rest_pre_serve_request` filter-hook.
*
* @param bool $served Whether the request has already been served.
* @param WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`.
* @param WP_REST_Request $request Request used to generate the response.
* @param WP_REST_Server $server Server instance.
*
* @return bool
*/
function wp_kama_rest_pre_serve_request_filter( $served, $result, $request, $server ){
// filter...
return $served;
}
- $served(true|false)
- Whether the request has already been served.
Default: false - $result(WP_HTTP_Response)
- Result to send to the client. Usually a
WP_REST_Response. - $request(WP_REST_Request)
- Request used to generate the response.
- $server(WP_REST_Server)
- Server instance.
Changelog
| Since 4.4.0 | Introduced. |
Where the hook is called
rest_pre_serve_request
wp-includes/rest-api/class-wp-rest-server.php 510
$served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
Where the hook is used in WordPress
wp-includes/default-filters.php 711
add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );
wp-includes/rest-api.php 252
add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );