rest_pre_dispatch
Filters the pre-calculated result of a REST API dispatch request.
Allow hijacking the request before dispatching by returning a non-empty. The returned value will be used to serve the request instead.
Usage
add_filter( 'rest_pre_dispatch', 'wp_kama_rest_pre_dispatch_filter', 10, 3 );
/**
* Function for `rest_pre_dispatch` filter-hook.
*
* @param mixed $result Response to replace the requested version with. Can be anything a normal endpoint can return, or null to not hijack the request.
* @param WP_REST_Server $server Server instance.
* @param WP_REST_Request $request Request used to generate the response.
*
* @return mixed
*/
function wp_kama_rest_pre_dispatch_filter( $result, $server, $request ){
// filter...
return $result;
}
- $result(mixed)
- Response to replace the requested version with. Can be anything a normal endpoint can return, or null to not hijack the request.
- $server(WP_REST_Server)
- Server instance.
- $request(WP_REST_Request)
- Request used to generate the response.
Changelog
| Since 4.4.0 | Introduced. |
Where the hook is called
rest_pre_dispatch
rest_pre_dispatch
wp-includes/rest-api/class-wp-rest-server.php 1073
$result = apply_filters( 'rest_pre_dispatch', null, $this, $request );
wp-includes/rest-api/class-wp-rest-server.php 1833
$result = apply_filters( 'rest_pre_dispatch', null, $this, $clean_request );
Where the hook is used in WordPress
wp-includes/rest-api.php 256
add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 );