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 914944656e..391f549f3a 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -260,10 +260,11 @@ class WP_REST_Server { * Filters whether the REST API is enabled. * * @since 4.4.0 + * @deprecated 4.7.0 Use the rest_authentication_errors filter to restrict access to the API * * @param bool $rest_enabled Whether the REST API is enabled. Default true. */ - $enabled = apply_filters( 'rest_enabled', true ); + apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', __( 'The REST API can no longer be completely disabled, the rest_authentication_errors can be used to restrict access to the API, instead.' ) ); /** * Filters whether jsonp is enabled. @@ -276,10 +277,6 @@ class WP_REST_Server { $jsonp_callback = null; - if ( ! $enabled ) { - echo $this->json_error( 'rest_disabled', __( 'The REST API is disabled on this site.' ), 404 ); - return false; - } if ( isset( $_GET['_jsonp'] ) ) { if ( ! $jsonp_enabled ) { echo $this->json_error( 'rest_callback_disabled', __( 'JSONP support is disabled on this site.' ), 400 ); diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 88ae9b7814..cda4a4f4cc 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -727,6 +727,20 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { $this->assertEquals( 'noindex', $headers['X-Robots-Tag'] ); } + /** + * @ticket 38446 + * @expectedDeprecated rest_enabled + */ + public function test_rest_enable_filter_is_deprecated() { + add_filter( 'rest_enabled', '__return_false' ); + $this->server->serve_request( '/' ); + remove_filter( 'rest_enabled', '__return_false' ); + + $result = json_decode( $this->server->sent_body ); + + $this->assertObjectNotHasAttribute( 'code', $result ); + } + public function test_link_header_on_requests() { $api_root = get_rest_url();