From 84d9dcb1e637b4c1928f0251d25cffc2d6e41bad Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 26 Oct 2016 06:27:04 +0000 Subject: [PATCH] REST API: Deprecate the `rest_enabled` filter. As the REST API becomes more integral to WordPress Core, turning it off will cause a... suboptimal experience. If we don't want it to be turned off, the off switch needs to be removed. Props jorbin, pento. Fixes #38446. git-svn-id: https://develop.svn.wordpress.org/trunk@38947 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rest-api/class-wp-rest-server.php | 7 ++----- tests/phpunit/tests/rest-api/rest-server.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) 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();