Make WordPress Core

Ticket #45753: 45753.1.diff

File 45753.1.diff, 1.2 KB (added by killua99, 6 years ago)

WIP: Currently it does what the ticket said to do. On my TODO list are, the Unit Test and perhaps some minor tweaks. I would like to get some help with the authentication level on my local test I'm not able to do a Basic authentication.

  • src/wp-includes/rest-api.php

    diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
    index 59e9f7931c..51658ed49c 100644
    a b function rest_handle_options_request( $response, $handler, $request ) { 
    616616        $data     = [];
    617617
    618618        foreach ( $handler->get_routes() as $route => $endpoints ) {
    619                 $match = preg_match( '@^' . $route . '$@i', $request->get_route() );
     619                $match = preg_match( '@^' . $route . '$@i', $request->get_route(), $matches );
    620620
    621621                if ( ! $match ) {
    622622                        continue;
    623623                }
    624624
     625                $args = [];
     626                foreach ( $matches as $param => $value ) {
     627                        if ( ! is_int( $param ) ) {
     628                                $args[ $param ] = $value;
     629                        }
     630                }
     631
     632                foreach ( $endpoints as $endpoint ) {
     633                        // Remove the redundant preg_match argument.
     634                        unset( $args[0] );
     635
     636                        $request->set_url_params( $args );
     637                        $request->set_attributes( $endpoint );
     638                }
     639
    625640                $data = $handler->get_data_for_route( $route, $endpoints, 'help' );
    626641                $response->set_matched_route( $route );
    627642                break;
    628643        }
    629644
    630         $response->set_data( $data );
    631 
    632645        $response = rest_send_allow_header( $response, $handler, $request );
    633646
     647        $response->set_data( $data );
     648
    634649        return $response;
    635650}
    636651