CodeExplorer get_routes example
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 );
} else { $routes =
$this->
get_routes();
} foreach ( $routes as $route =>
$handlers ) { $match =
preg_match( '@^' .
$route . '$@i',
$path,
$matches );
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;
} }