apply_filters( 'rest_pre_dispatch', mixed $result, WP_REST_Server $server, WP_REST_Request $request )
- Since
- 4.4.0
Filters the pre-calculated result of a REST API dispatch request.
Description
Allow hijacking the request before dispatching by returning a non-empty. The returned value will be used to serve the request instead.
Compatibility
- WordPress
- since 4.4.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Parameters
$resultmixed- Response to replace the requested version with. Can be anything a normal endpoint can return, or null to not hijack the request.
$serverWP_REST_Server- Server instance.
$requestWP_REST_Request- Request used to generate the response.
Where this hook fires · 2
wp-includes/rest-api/class-wp-rest-server.php:1084WP_REST_Server::dispatch()wp-includes/rest-api/class-wp-rest-server.php:1845WP_REST_Server::serve_batch_request_v1()
Source code
* * @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. */ $result = apply_filters( 'rest_pre_dispatch', null, $this, $request ); if ( ! empty( $result ) ) { // Normalize to either WP_Error or WP_REST_Response... $result = rest_ensure_response( $result );Changelog
Introduced in 4.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.