diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php
index acf23f4dda..a4346214f4 100644
|
a
|
b
|
class WP_REST_Server {
|
| 744 | 744 | * used as the delimiter with preg_match() |
| 745 | 745 | * |
| 746 | 746 | * @since 4.4.0 |
| | 747 | * @since 5.4.0 Add $filter parameter. |
| 747 | 748 | * |
| | 749 | * @param array $filter Optionally, filter the list of routes before normalization. |
| 748 | 750 | * @return array `'/path/regex' => array( $callback, $bitmask )` or |
| 749 | 751 | * `'/path/regex' => array( array( $callback, $bitmask ), ...)`. |
| 750 | 752 | */ |
| 751 | | public function get_routes() { |
| | 753 | public function get_routes( $filter = array() ) { |
| | 754 | $endpoints = $this->endpoints; |
| | 755 | |
| | 756 | if ( $filter ) { |
| | 757 | $endpoints = wp_list_filter( $endpoints, $filter ); |
| | 758 | } |
| 752 | 759 | |
| 753 | 760 | /** |
| 754 | 761 | * Filters the array of available endpoints. |
| … |
… |
class WP_REST_Server {
|
| 760 | 767 | * `'/path/regex' => array( $callback, $bitmask )` or |
| 761 | 768 | * `'/path/regex' => array( array( $callback, $bitmask ). |
| 762 | 769 | */ |
| 763 | | $endpoints = apply_filters( 'rest_endpoints', $this->endpoints ); |
| | 770 | $endpoints = apply_filters( 'rest_endpoints', $endpoints ); |
| 764 | 771 | |
| 765 | 772 | // Normalise the endpoints. |
| 766 | 773 | $defaults = array( |
| … |
… |
class WP_REST_Server {
|
| 872 | 879 | $method = $request->get_method(); |
| 873 | 880 | $path = $request->get_route(); |
| 874 | 881 | |
| 875 | | foreach ( $this->get_routes() as $route => $handlers ) { |
| | 882 | $routes = array(); |
| | 883 | |
| | 884 | foreach ( $this->get_namespaces() as $namespace ) { |
| | 885 | if ( 0 === strpos( ltrim( $path, '/' ), $namespace ) ) { |
| | 886 | $routes = $this->get_routes( array( 'namespace' => $namespace ) ); |
| | 887 | break; |
| | 888 | } |
| | 889 | } |
| | 890 | |
| | 891 | if ( ! $routes ) { |
| | 892 | $routes = $this->get_routes(); |
| | 893 | } |
| | 894 | |
| | 895 | foreach ( $routes as $route => $handlers ) { |
| 876 | 896 | $match = preg_match( '@^' . $route . '$@i', $path, $matches ); |
| 877 | 897 | |
| 878 | 898 | if ( ! $match ) { |
diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
index abfdefcd0b..72b2a08e73 100644
|
a
|
b
|
class Tests_REST_Server extends WP_Test_REST_TestCase {
|
| 1431 | 1431 | ); |
| 1432 | 1432 | } |
| 1433 | 1433 | |
| | 1434 | /** |
| | 1435 | * @ticket 48530 |
| | 1436 | */ |
| | 1437 | public function test_get_routes_respects_namespace_parameter() { |
| | 1438 | $routes = rest_get_server()->get_routes( array( 'namespace' => 'oembed/1.0' ) ); |
| | 1439 | $this->assertGreaterThan( 0, count( $routes ) ); |
| | 1440 | |
| | 1441 | foreach ( $routes as $route => $handlers ) { |
| | 1442 | $this->assertStringStartsWith( '/oembed/1.0', $route ); |
| | 1443 | } |
| | 1444 | } |
| | 1445 | |
| 1434 | 1446 | public function _validate_as_integer_123( $value, $request, $key ) { |
| 1435 | 1447 | if ( ! is_int( $value ) ) { |
| 1436 | 1448 | return new WP_Error( 'some-error', 'This is not valid!' ); |