Filter hook 'rest_dispatch_request'

in WP Core File wp-includes/rest-api/class-wp-rest-server.php at line 1286

View Source

rest_dispatch_request

Filter Hook
Description
Filters the REST API dispatch request result. Allow plugins to override dispatching the request.

Hook Information

File Location wp-includes/rest-api/class-wp-rest-server.php View on GitHub
Hook Type Filter
Line Number 1286

Hook Parameters

Type Name Description
mixed $dispatch_result Dispatch result, will be used if not empty.
WP_REST_Request $request Request used to generate the response.
string $route Route matched for the request.
array $handler Route handler used for the request.

Usage Examples

Basic Usage
<?php
// Hook into rest_dispatch_request
add_filter('rest_dispatch_request', 'my_custom_filter', 10, 4);

function my_custom_filter($dispatch_result, $request, $route, $handler) {
    // Your custom filtering logic here
    return $dispatch_result;
}

Source Code Context

wp-includes/rest-api/class-wp-rest-server.php:1286 - How this hook is used in WordPress core
<?php
1281  			 * @param mixed           $dispatch_result Dispatch result, will be used if not empty.
1282  			 * @param WP_REST_Request $request         Request used to generate the response.
1283  			 * @param string          $route           Route matched for the request.
1284  			 * @param array           $handler         Route handler used for the request.
1285  			 */
1286  			$dispatch_result = apply_filters( 'rest_dispatch_request', null, $request, $route, $handler );
1287  
1288  			// Allow plugins to halt the request via this filter.
1289  			if ( null !== $dispatch_result ) {
1290  				$response = $dispatch_result;
1291  			} else {

PHP Documentation

<?php
/**
			 * Filters the REST API dispatch request result.
			 *
			 * Allow plugins to override dispatching the request.
			 *
			 * @since 4.4.0
			 * @since 4.5.0 Added `$route` and `$handler` parameters.
			 *
			 * @param mixed           $dispatch_result Dispatch result, will be used if not empty.
			 * @param WP_REST_Request $request         Request used to generate the response.
			 * @param string          $route           Route matched for the request.
			 * @param array           $handler         Route handler used for the request.
			 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/rest-api/class-wp-rest-server.php
Related Hooks

Related hooks will be displayed here in future updates.