Make WordPress Core


Ignore:
Timestamp:
03/19/2019 03:21:28 AM (6 years ago)
Author:
kadamwhite
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r44698 r44933  
    616616
    617617    foreach ( $handler->get_routes() as $route => $endpoints ) {
    618         $match = preg_match( '@^' . $route . '$@i', $request->get_route() );
     618        $match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches );
    619619
    620620        if ( ! $match ) {
    621621            continue;
     622        }
     623
     624        $args = array();
     625        foreach ( $matches as $param => $value ) {
     626            if ( ! is_int( $param ) ) {
     627                $args[ $param ] = $value;
     628            }
     629        }
     630
     631        foreach ( $endpoints as $endpoint ) {
     632            // Remove the redundant preg_match argument.
     633            unset( $args[0] );
     634
     635            $request->set_url_params( $args );
     636            $request->set_attributes( $endpoint );
    622637        }
    623638
Note: See TracChangeset for help on using the changeset viewer.