rest_dispatch_request
Filters the REST API dispatch request result.
Allow plugins to override dispatching the request.
Использование
add_filter( 'rest_dispatch_request', 'wp_kama_rest_dispatch_request_filter', 10, 4 );
/**
* Function for `rest_dispatch_request` filter-hook.
*
* @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.
*
* @return mixed
*/
function wp_kama_rest_dispatch_request_filter( $dispatch_result, $request, $route, $handler ){
// filter...
return $dispatch_result;
}
- $dispatch_result(разное)
- Dispatch result, will be used if not empty.
- $request(WP_REST_Request)
- Request used to generate the response.
- $route(строка)
- Route matched for the request.
- $handler(массив)
- Route handler used for the request.
Список изменений
| С версии 4.4.0 | Введена. |
| С версии 4.5.0 | Added $route and $handler parameters. |
Где вызывается хук
wp-includes/rest-api/class-wp-rest-server.php 1281
$dispatch_result = apply_filters( 'rest_dispatch_request', null, $request, $route, $handler );