Changeset 47260
- Timestamp:
- 02/11/2020 03:20:05 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r47239 r47260 745 745 * 746 746 * @since 4.4.0 747 * 747 * @since 5.4.0 Add $namespace parameter. 748 * 749 * @param string $namespace Optionally, only return routes in the given namespace. 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( $namespace = '' ) { 754 $endpoints = $this->endpoints; 755 756 if ( $namespace ) { 757 $endpoints = wp_list_filter( $endpoints, array( 'namespace' => $namespace ) ); 758 } 752 759 753 760 /** … … 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. … … 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( $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 -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r47239 r47260 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( 'oembed/1.0' ); 1439 1440 foreach ( $routes as $route => $handlers ) { 1441 $this->assertStringStartsWith( '/oembed/1.0', $route ); 1442 } 1443 } 1444 1434 1445 public function _validate_as_integer_123( $value, $request, $key ) { 1435 1446 if ( ! is_int( $value ) ) {
Note: See TracChangeset
for help on using the changeset viewer.