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 62f7343069..2c46fd8d58 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -780,7 +780,8 @@ class WP_REST_Server { $callback = $handler['callback']; $response = null; - if ( empty( $handler['methods'][ $method ] ) ) { + $checked_method = 'HEAD' === $method ? 'GET' : $method; + if ( empty( $handler['methods'][ $checked_method ] ) ) { continue; } diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 248ba56740..c9431f0954 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -121,6 +121,16 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertEquals( array( 'foo' => 'bar' ), $request->get_params() ); } + public function test_head_request_handled_by_get() { + register_rest_route( 'head-request', '/test', array( + 'methods' => array( 'GET' ), + 'callback' => '__return_true', + ) ); + $request = new WP_REST_Request( 'HEAD', '/head-request/test' ); + $response = $this->server->dispatch( $request ); + $this->assertEquals( 200, $response->get_status() ); + } + /** * Pass a capability which the user does not have, this should * result in a 403 error.