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
This commit is contained in:
parent
9b8697aea3
commit
84d9dcb1e6
@ -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 );
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user