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 efda2321b7..2a7cb268a1 100644
|
a
|
b
|
class WP_REST_Server { |
| 879 | 879 | $method = $request->get_method(); |
| 880 | 880 | $path = $request->get_route(); |
| 881 | 881 | |
| 882 | | $routes = array(); |
| | 882 | $with_namespace = array(); |
| 883 | 883 | |
| 884 | 884 | foreach ( $this->get_namespaces() as $namespace ) { |
| 885 | | if ( 0 === strpos( ltrim( $path, '/' ), $namespace ) ) { |
| 886 | | $routes = $this->get_routes( $namespace ); |
| 887 | | break; |
| | 885 | if ( 0 === strpos( trailingslashit( ltrim( $path, '/' ) ), $namespace ) ) { |
| | 886 | $with_namespace[] = $this->get_routes( $namespace ); |
| 888 | 887 | } |
| 889 | 888 | } |
| 890 | 889 | |
| 891 | | if ( ! $routes ) { |
| | 890 | if ( $with_namespace ) { |
| | 891 | $routes = array_merge( ...$with_namespace ); |
| | 892 | } else { |
| 892 | 893 | $routes = $this->get_routes(); |
| 893 | 894 | } |
| 894 | 895 | |
diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
index 755f0296ea..16838bd724 100644
|
a
|
b
|
class Tests_REST_Server extends WP_Test_REST_TestCase { |
| 1442 | 1442 | } |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| | 1445 | /** |
| | 1446 | * @ticket 48530 |
| | 1447 | */ |
| | 1448 | public function test_get_routes_no_namespace_overriding() { |
| | 1449 | register_rest_route( |
| | 1450 | 'test-ns', |
| | 1451 | '/test', |
| | 1452 | array( |
| | 1453 | 'methods' => array( 'GET' ), |
| | 1454 | 'callback' => function() { |
| | 1455 | return new WP_REST_Response( 'data', 204 ); |
| | 1456 | }, |
| | 1457 | ) |
| | 1458 | ); |
| | 1459 | register_rest_route( |
| | 1460 | 'test-ns/v1', |
| | 1461 | '/test', |
| | 1462 | array( |
| | 1463 | 'methods' => array( 'GET' ), |
| | 1464 | 'callback' => function() { |
| | 1465 | return new WP_REST_Response( 'data', 204 ); |
| | 1466 | }, |
| | 1467 | ) |
| | 1468 | ); |
| | 1469 | |
| | 1470 | $request = new WP_REST_Request( 'GET', '/test-ns/v1/test' ); |
| | 1471 | $response = rest_get_server()->dispatch( $request ); |
| | 1472 | |
| | 1473 | $this->assertEquals( 204, $response->get_status(), '/test-ns/v1/test' ); |
| | 1474 | } |
| | 1475 | |
| 1445 | 1476 | public function _validate_as_integer_123( $value, $request, $key ) { |
| 1446 | 1477 | if ( ! is_int( $value ) ) { |
| 1447 | 1478 | return new WP_Error( 'some-error', 'This is not valid!' ); |