rest_dispatch_request

Filters the REST dispatch request result.

Description

apply_filters( 'rest_dispatch_request', (null) $null, (WP_REST_Request) $request, (string) $route, (array) $handler ); 

Allow plugins to override dispatching the request.

Parameters (4)

0. $null (null) => null
Dispatch result, will be used if not empty.
1. $request (WP_REST_Request)
Request used to generate the response.
2. $route (string)
Route matched for the request.
3. $handler (array)
Route handler used for the request.

Usage

To run the hook, copy the example below.
  1. $null = apply_filters( 'rest_dispatch_request', $null, $request, $route, $handler ); 
  2.  
  3. if ( !empty( $null ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the rest_dispatch_request callback 
  2. function filter_rest_dispatch_request( $null, $request, $route, $handler ) { 
  3. // make filter magic happen here... 
  4. return $null
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'rest_dispatch_request', 'filter_rest_dispatch_request', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'rest_dispatch_request', 'filter_rest_dispatch_request', 10, 4 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/rest-api/class-wp-rest-server.php  
  1. $dispatch_result = apply_filters( 'rest_dispatch_request', null, $request, $route, $handler );