set_query_params example

            $api_url_part = substr( $urlstrlen( untrailingslashit( $api_root ) ) );
            $route        = parse_url( $api_url_part, PHP_URL_PATH );
        } elseif ( ! empty( $query_params['rest_route'] ) ) {
            // ?rest_route=... set directly.             $route = $query_params['rest_route'];
            unset( $query_params['rest_route'] );
        }

        $request = false;
        if ( ! empty( $route ) ) {
            $request = new WP_REST_Request( 'GET', $route );
            $request->set_query_params( $query_params );
        }

        /** * Filters the REST API request generated from a URL. * * @since 4.5.0 * * @param WP_REST_Request|false $request Generated request object, or false if URL * could not be parsed. * @param string $url URL the request was generated from. */
        
if ( empty( $path ) ) {
            if ( isset( $_SERVER['PATH_INFO'] ) ) {
                $path = $_SERVER['PATH_INFO'];
            } else {
                $path = '/';
            }
        }

        $request = new WP_REST_Request( $_SERVER['REQUEST_METHOD']$path );

        $request->set_query_params( wp_unslash( $_GET ) );
        $request->set_body_params( wp_unslash( $_POST ) );
        $request->set_file_params( $_FILES );
        $request->set_headers( $this->get_headers( wp_unslash( $_SERVER ) ) );
        $request->set_body( self::get_raw_data() );

        /* * HTTP method override for clients that can't use PUT/PATCH/DELETE. First, we check * $_GET['_method']. If that is not set, we check for the HTTP_X_HTTP_METHOD_OVERRIDE * header. */
        if ( isset( $_GET['_method'] ) ) {
            
$path = '/';
    }

    $path_parts = parse_url( $path );
    if ( false === $path_parts ) {
        return $memo;
    }

    $request = new WP_REST_Request( $method$path_parts['path'] );
    if ( ! empty( $path_parts['query'] ) ) {
        parse_str( $path_parts['query']$query_params );
        $request->set_query_params( $query_params );
    }

    $response = rest_do_request( $request );
    if ( 200 === $response->status ) {
        $server = rest_get_server();
        /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
        $response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response )$server$request );
        $embed    = $request->has_param( '_embed' ) ? rest_parse_embed_param( $request['_embed'] ) : false;
        $data     = (array) $server->response_to_data( $response$embed );

        if ( 'OPTIONS' === $method ) {
            
Home | Imprint | This part of the site doesn't use cookies.