WordPress.org

Make WordPress Core

Ticket #38446: 38446.2.diff

File 38446.2.diff, 2.0 KB (added by pento, 3 years ago)
  • src/wp-includes/rest-api/class-wp-rest-server.php

     
    260260                 * Filters whether the REST API is enabled.
    261261                 *
    262262                 * @since 4.4.0
     263                 * @deprecated 4.7.0 Use the rest_authentication_errors filter to restrict access to the API
    263264                 *
    264265                 * @param bool $rest_enabled Whether the REST API is enabled. Default true.
    265266                 */
    266                 $enabled = apply_filters( 'rest_enabled', true );
     267                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.' ) );
    267268
    268269                /**
    269270                 * Filters whether jsonp is enabled.
     
    276277
    277278                $jsonp_callback = null;
    278279
    279                 if ( ! $enabled ) {
    280                         echo $this->json_error( 'rest_disabled', __( 'The REST API is disabled on this site.' ), 404 );
    281                         return false;
    282                 }
    283280                if ( isset( $_GET['_jsonp'] ) ) {
    284281                        if ( ! $jsonp_enabled ) {
    285282                                echo $this->json_error( 'rest_callback_disabled', __( 'JSONP support is disabled on this site.' ), 400 );
  • tests/phpunit/tests/rest-api/rest-server.php

     
    727727                $this->assertEquals( 'noindex', $headers['X-Robots-Tag'] );
    728728        }
    729729
     730        /**
     731         * @ticket 38446
     732         * @expectedDeprecated rest_enabled
     733         */
     734        public function test_rest_enable_filter_is_deprecated() {
     735                add_filter( 'rest_enabled', '__return_false' );
     736                $this->server->serve_request( '/' );
     737                remove_filter( 'rest_enabled', '__return_false' );
     738
     739                $result = json_decode( $this->server->sent_body );
     740
     741                $this->assertObjectNotHasAttribute( 'code', $result );
     742        }
     743
    730744        public function test_link_header_on_requests() {
    731745                $api_root = get_rest_url();
    732746