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 e07e214d97..e85f4a4386 100644
|
a
|
b
|
class WP_REST_Server { |
| 706 | 706 | * used as the delimiter with preg_match() |
| 707 | 707 | * |
| 708 | 708 | * @since 4.4.0 |
| | 709 | * @since 5.4.0 Add $namespace parameter. |
| 709 | 710 | * |
| | 711 | * @param string $namespace Optionally, only return routes in the given namespace. |
| 710 | 712 | * @return array `'/path/regex' => array( $callback, $bitmask )` or |
| 711 | 713 | * `'/path/regex' => array( array( $callback, $bitmask ), ...)`. |
| 712 | 714 | */ |
| 713 | | public function get_routes() { |
| | 715 | public function get_routes( $namespace = '' ) { |
| | 716 | $endpoints = $this->endpoints; |
| | 717 | |
| | 718 | if ( $namespace ) { |
| | 719 | $endpoints = wp_list_filter( $endpoints, array( 'namespace' => $namespace ) ); |
| | 720 | } |
| 714 | 721 | |
| 715 | 722 | /** |
| 716 | 723 | * Filters the array of available endpoints. |
| … |
… |
class WP_REST_Server { |
| 722 | 729 | * `'/path/regex' => array( $callback, $bitmask )` or |
| 723 | 730 | * `'/path/regex' => array( array( $callback, $bitmask ). |
| 724 | 731 | */ |
| 725 | | $endpoints = apply_filters( 'rest_endpoints', $this->endpoints ); |
| | 732 | $endpoints = apply_filters( 'rest_endpoints', $endpoints ); |
| 726 | 733 | |
| 727 | 734 | // Normalise the endpoints. |
| 728 | 735 | $defaults = array( |
| … |
… |
class WP_REST_Server { |
| 834 | 841 | $method = $request->get_method(); |
| 835 | 842 | $path = $request->get_route(); |
| 836 | 843 | |
| 837 | | foreach ( $this->get_routes() as $route => $handlers ) { |
| | 844 | $routes = array(); |
| | 845 | |
| | 846 | foreach ( $this->get_namespaces() as $namespace ) { |
| | 847 | if ( 0 === strpos( ltrim( $path, '/' ), $namespace ) ) { |
| | 848 | $routes = $this->get_routes( $namespace ); |
| | 849 | break; |
| | 850 | } |
| | 851 | } |
| | 852 | |
| | 853 | if ( ! $routes ) { |
| | 854 | $routes = $this->get_routes(); |
| | 855 | } |
| | 856 | |
| | 857 | foreach ( $routes as $route => $handlers ) { |
| 838 | 858 | $match = preg_match( '@^' . $route . '$@i', $path, $matches ); |
| 839 | 859 | |
| 840 | 860 | if ( ! $match ) { |
diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
index 74d957cbe5..6f4ab5c0a1 100644
|
a
|
b
|
class Tests_REST_Server extends WP_Test_REST_TestCase { |
| 1211 | 1211 | $this->assertEquals( '', rest_get_server()->sent_body ); |
| 1212 | 1212 | } |
| 1213 | 1213 | |
| | 1214 | /** |
| | 1215 | * @ticket 48530 |
| | 1216 | */ |
| | 1217 | public function test_get_routes_respects_namespace_parameter() { |
| | 1218 | $routes = rest_get_server()->get_routes( 'oembed/1.0' ); |
| | 1219 | |
| | 1220 | foreach ( $routes as $route => $handlers ) { |
| | 1221 | $this->assertStringStartsWith( '/oembed/1.0', $route ); |
| | 1222 | } |
| | 1223 | } |
| | 1224 | |
| 1214 | 1225 | public function _validate_as_integer_123( $value, $request, $key ) { |
| 1215 | 1226 | if ( ! is_int( $value ) ) { |
| 1216 | 1227 | return new WP_Error( 'some-error', 'This is not valid!' ); |