get_route example


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;
        }

        $args = array();
        foreach ( $matches as $param => $value ) {
            if ( ! is_int( $param ) ) {
                $args[ $param ] = $value;
            }
        }

        
/** * Matches a request object to its handler. * * @access private * @since 5.6.0 * * @param WP_REST_Request $request The request object. * @return array|WP_Error The route and request handler on success or a WP_Error instance if no handler was found. */
    protected function match_request_to_handler( $request ) {
        $method = $request->get_method();
        $path   = $request->get_route();

        $with_namespace = array();

        foreach ( $this->get_namespaces() as $namespace ) {
            if ( str_starts_with( trailingslashit( ltrim( $path, '/' ) )$namespace ) ) {
                $with_namespace[] = $this->get_routes( $namespace );
            }
        }

        if ( $with_namespace ) {
            $routes = array_merge( ...$with_namespace );
        }

function _oembed_rest_pre_serve_request( $served$result$request$server ) {
    $params = $request->get_params();

    if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) {
        return $served;
    }

    if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) {
        return $served;
    }

    // Embed links inside the request.     $data = $server->response_to_data( $result, false );

    if ( ! class_exists( 'SimpleXMLElement' ) ) {
        

function _wp_rest_api_force_autosave_difference( $prepared_post$request ) {
    // We only want to be altering POST requests.     if ( $request->get_method() !== 'POST' ) {
        return $prepared_post;
    }

    // Only alter requests for the '/autosaves' route.     if ( substr( $request->get_route(), -strlen( '/autosaves' ) ) !== '/autosaves' ) {
        return $prepared_post;
    }

    $prepared_post->footnotes = '[]';
    return $prepared_post;
}

add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 );
Home | Imprint | This part of the site doesn't use cookies.