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 c7ffb5b7677d0..af12d02b51cb0 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -1007,7 +1007,11 @@ public function get_routes( $route_namespace = '' ) { if ( is_string( $handler['methods'] ) ) { $methods = explode( ',', $handler['methods'] ); } elseif ( is_array( $handler['methods'] ) ) { - $methods = $handler['methods']; + $methods = array(); + + foreach ( $handler['methods'] as $method ) { + $methods = array_merge( $methods, explode( ',', $method ) ); + } } else { $methods = array(); } diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index fcb8e3da87f4c..0475b586d182d 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -362,6 +362,33 @@ public function test_route_method_comma_separated() { ); } + /** + * @ticket 65905 + */ + public function test_route_method_array_with_comma_separated_values() { + register_rest_route( + 'test-ns', + '/test', + array( + 'methods' => array( 'GET', 'POST, PUT, PATCH' ), + 'callback' => '__return_null', + 'permission_callback' => '__return_true', + ) + ); + + $routes = $GLOBALS['wp_rest_server']->get_routes(); + + $this->assertSame( + array( + 'GET' => true, + 'POST' => true, + 'PUT' => true, + 'PATCH' => true, + ), + $routes['/test-ns/test'][0]['methods'] + ); + } + public function test_options_request() { register_rest_route( 'test-ns',