Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/wp-includes/rest-api/class-wp-rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/tests/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading