Summery Summery
Sends the “Allow” header to state all methods that can be sent to the current route.
Syntax Syntax
Parameters Parameters
- $response
-
(Required) Current response being served.
- $server
-
(Required) ResponseHandler instance (usually WP_REST_Server).
- $request
-
(Required) The request that was used to make current response.
Return Return
(WP_REST_Response) Response to be served, with "Allow" header if route has allowed methods.
Source Source
File: wp-includes/rest-api.php
header( 'Vary: Origin', false );
} elseif ( ! headers_sent() && 'GET' === $_SERVER['REQUEST_METHOD'] && ! is_user_logged_in() ) {
header( 'Vary: Origin', false );
}
return $value;
}
/**
* Handles OPTIONS requests for the server.
*
* This is handled outside of the server code, as it doesn't obey normal route
* mapping.
*
* @since 4.4.0
*
* @param mixed $response Current response, either response or `null` to indicate pass-through.
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
* @param WP_REST_Request $request The request that was used to make current response.
* @return WP_REST_Response Modified response, either response or `null` to indicate pass-through.
*/
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;
}
Advertisement
Changelog Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |