rest_handle_options_request()
Handles OPTIONS requests for the server.
This is handled outside of the server code, as it doesn't obey normal route mapping.
Хуков нет.
Возвращает
WP_REST_Response. Modified response, either response or null to indicate pass-through.
Использование
rest_handle_options_request( $response, $handler, $request );
- $response(разное) (обязательный)
- Current response, either response or
nullto indicate pass-through. - $handler(WP_REST_Server) (обязательный)
- ResponseHandler instance (usually WP_REST_Server).
- $request(WP_REST_Request) (обязательный)
- The request that was used to make current response.
Список изменений
| С версии 4.4.0 | Введена. |
Код rest_handle_options_request() rest handle options request WP 6.9.1
function rest_handle_options_request( $response, $handler, $request ) {
if ( ! empty( $response ) || $request->get_method() !== 'OPTIONS' ) {
return $response;
}
$response = new WP_REST_Response();
$data = array();
foreach ( $handler->get_routes() as $route => $endpoints ) {
$match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches );
if ( ! $match ) {
continue;
}
$args = array();
foreach ( $matches as $param => $value ) {
if ( ! is_int( $param ) ) {
$args[ $param ] = $value;
}
}
foreach ( $endpoints as $endpoint ) {
$request->set_url_params( $args );
$request->set_attributes( $endpoint );
}
$data = $handler->get_data_for_route( $route, $endpoints, 'help' );
$response->set_matched_route( $route );
break;
}
$response->set_data( $data );
return $response;
}