REST API: Ensure "Allow" header is returned for OPTIONS requests.
This changeset ensures `$request->set_url_params()` is called while fulfilling OPTIONS requests, where previously it was skipped because OPTIONS requests short-circuit the logic in `dispatch` which handles this setup for other request methods. Omitting the URL parameters prevented the Allow header from being set. Props killua99, noisysocks. Fixes #45753. Built from https://develop.svn.wordpress.org/trunk@44933 git-svn-id: http://core.svn.wordpress.org/trunk@44764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
574f7a221f
commit
391d481fe1
|
@ -615,12 +615,27 @@ function rest_handle_options_request( $response, $handler, $request ) {
|
|||
$data = array();
|
||||
|
||||
foreach ( $handler->get_routes() as $route => $endpoints ) {
|
||||
$match = preg_match( '@^' . $route . '$@i', $request->get_route() );
|
||||
$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 ) {
|
||||
// Remove the redundant preg_match argument.
|
||||
unset( $args[0] );
|
||||
|
||||
$request->set_url_params( $args );
|
||||
$request->set_attributes( $endpoint );
|
||||
}
|
||||
|
||||
$data = $handler->get_data_for_route( $route, $endpoints, 'help' );
|
||||
$response->set_matched_route( $route );
|
||||
break;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.2-alpha-44932';
|
||||
$wp_version = '5.2-alpha-44933';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue