WP_REST_Server::dispatch() public WP 4.4.0
Matches the request to a callback and call it.
{} Это метод класса: WP_REST_Server{}
Хуки из метода
Возвращает
WP_REST_Response. Response returned by the callback.
Использование
$WP_REST_Server = new WP_REST_Server(); $WP_REST_Server->dispatch( $request );
- $request(WP_REST_Request) (обязательный)
- Request to attempt dispatching.
Список изменений
С версии 4.4.0 | Введена. |
Код WP_REST_Server::dispatch() WP REST Server::dispatch WP 5.6.2
public function dispatch( $request ) {
/**
* Filters the pre-calculated result of a REST dispatch request.
*
* Allow hijacking the request before dispatching by returning a non-empty. The returned value
* will be used to serve the request instead.
*
* @since 4.4.0
*
* @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 $this 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 ) ) {
return $result;
}
$error = null;
$matched = $this->match_request_to_handler( $request );
if ( is_wp_error( $matched ) ) {
return $this->error_to_response( $matched );
}
list( $route, $handler ) = $matched;
if ( ! is_callable( $handler['callback'] ) ) {
$error = new WP_Error(
'rest_invalid_handler',
__( 'The handler for the route is invalid.' ),
array( 'status' => 500 )
);
}
if ( ! is_wp_error( $error ) ) {
$check_required = $request->has_valid_params();
if ( is_wp_error( $check_required ) ) {
$error = $check_required;
} else {
$check_sanitized = $request->sanitize_params();
if ( is_wp_error( $check_sanitized ) ) {
$error = $check_sanitized;
}
}
}
return $this->respond_to_request( $request, $route, $handler, $error );
}