Make WordPress Core

Ticket #34219: 34219.diff

File 34219.diff, 6.5 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index cfdd709..4df448c 100644
    add_filter( 'title_save_pre', 'trim' ); 
    204204
    205205add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
    206206
    207 // REST API filters.
    208 add_action( 'xmlrpc_rsd_apis',            'rest_output_rsd' );
    209 add_action( 'wp_head',                    'rest_output_link_wp_head', 10, 0 );
    210 add_action( 'template_redirect',          'rest_output_link_header', 11, 0 );
    211 add_action( 'auth_cookie_malformed',      'rest_cookie_collect_status' );
    212 add_action( 'auth_cookie_expired',        'rest_cookie_collect_status' );
    213 add_action( 'auth_cookie_bad_username',   'rest_cookie_collect_status' );
    214 add_action( 'auth_cookie_bad_hash',       'rest_cookie_collect_status' );
    215 add_action( 'auth_cookie_valid',          'rest_cookie_collect_status' );
    216 add_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );
    217 
    218207// Actions
    219208add_action( 'wp_head',             '_wp_render_title_tag',            1     );
    220209add_action( 'wp_head',             'wp_enqueue_scripts',              1     );
    add_action( 'after_password_reset', 'wp_password_change_notification' ); 
    358347add_action( 'register_new_user',      'wp_send_new_user_notifications' );
    359348add_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
    360349
    361 // REST API actions.
    362 add_action( 'init',          'rest_api_init' );
    363 add_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
    364 add_action( 'parse_request', 'rest_api_loaded' );
     350/*
     351 * REST API actions and filters.
     352 */
     353
     354add_action( 'init',                              'rest_api_init' );
     355add_action( 'parse_request',                     'rest_api_loaded' );
     356
     357// Deprecated reporting.
     358add_action( 'deprecated_function_run',           '_rest_handle_deprecated_function', 10, 3 );
     359add_filter( 'deprecated_function_trigger_error', '_rest_deprecated_trigger_error' );
     360add_action( 'deprecated_argument_run',           '_rest_handle_deprecated_argument', 10, 3 );
     361add_filter( 'deprecated_argument_trigger_error', '_rest_deprecated_trigger_error' );
     362
     363// Visibility
     364add_action( 'xmlrpc_rsd_apis',                   'rest_output_rsd' );
     365add_action( 'wp_head',                           'rest_output_link_wp_head', 10, 0 );
     366add_action( 'template_redirect',                 'rest_output_link_header', 11, 0 );
     367
     368// Authentication
     369add_action( 'auth_cookie_malformed',             'rest_cookie_collect_status' );
     370add_action( 'auth_cookie_expired',               'rest_cookie_collect_status' );
     371add_action( 'auth_cookie_bad_username',          'rest_cookie_collect_status' );
     372add_action( 'auth_cookie_bad_hash',              'rest_cookie_collect_status' );
     373add_action( 'auth_cookie_valid',                 'rest_cookie_collect_status' );
     374add_filter( 'rest_authentication_errors',        'rest_cookie_check_errors', 100 );
     375
     376// Default serving.
     377add_filter( 'rest_pre_serve_request',            'rest_send_cors_headers' );
     378add_filter( 'rest_post_dispatch',                'rest_send_allow_header', 10, 3 );
     379add_filter( 'rest_pre_dispatch',                 'rest_handle_options_request', 10, 3 );
    365380
    366381/**
    367382 * Filters formerly mixed into wp-includes
  • src/wp-includes/rest-api/rest-functions.php

    diff --git src/wp-includes/rest-api/rest-functions.php src/wp-includes/rest-api/rest-functions.php
    index 8a687f7..2ebf10a 100644
    function rest_api_register_rewrites() { 
    129129}
    130130
    131131/**
    132  * Registers the default REST API filters.
    133  *
    134  * @since 4.4.0
    135  *
    136  * @internal This will live in default-filters.php
    137  */
    138 function rest_api_default_filters() {
    139         // Deprecated reporting.
    140         add_action( 'deprecated_function_run', 'rest_handle_deprecated_function', 10, 3 );
    141         add_filter( 'deprecated_function_trigger_error', '__return_false' );
    142         add_action( 'deprecated_argument_run', 'rest_handle_deprecated_argument', 10, 3 );
    143         add_filter( 'deprecated_argument_trigger_error', '__return_false' );
    144 
    145         // Default serving.
    146         add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
    147         add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
    148 
    149         add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 );
    150 }
    151 
    152 /**
    153132 * Loads the REST API.
    154133 *
    155134 * @since 4.4.0
    function rest_ensure_response( $response ) { 
    342321 * Handles _deprecated_function() errors.
    343322 *
    344323 * @since 4.4.0
     324 * @access private
    345325 *
    346326 * @param string $function    Function name.
    347327 * @param string $replacement Replacement function name.
    348328 * @param string $version     Version.
    349329 */
    350 function rest_handle_deprecated_function( $function, $replacement, $version ) {
     330function _rest_handle_deprecated_function( $function, $replacement, $version ) {
    351331        if ( ! empty( $replacement ) ) {
    352332                $string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement );
    353333        } else {
    354334                $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version );
    355335        }
    356336
    357         header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) );
     337        if ( defined( 'REST_REQUEST' ) && ! headers_sent() ) {
     338                header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) );
     339        }
    358340}
    359341
    360342/**
    361343 * Handles _deprecated_argument() errors.
    362344 *
    363345 * @since 4.4.0
     346 * @access private
    364347 *
    365348 * @param string $function    Function name.
    366349 * @param string $replacement Replacement function name.
    367350 * @param string $version     Version.
    368351 */
    369 function rest_handle_deprecated_argument( $function, $replacement, $version ) {
     352function _rest_handle_deprecated_argument( $function, $replacement, $version ) {
    370353        if ( ! empty( $replacement ) ) {
    371354                $string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $replacement );
    372355        } else {
    373356                $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version );
    374357        }
    375358
    376         header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) );
     359        if ( defined( 'REST_REQUEST' ) && ! headers_sent() ) {
     360                header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) );
     361        }
     362}
     363
     364/**
     365 * Filters whether to trigger an error for deprecated functions
     366 * and arguments during a REST request.
     367 *
     368 * @since 4.4.0
     369 * @access private
     370 *
     371 * @param bool $trigger Whether to trigger the error for deprecated functions.
     372 * @return bool False when it is a REST Request, `$trigger` otherwise.
     373 */
     374function _rest_deprecated_trigger_error( $trigger ) {
     375        if ( defined( 'REST_REQUEST' ) ) {
     376                return false;
     377        }
     378
     379        return $trigger;
    377380}
    378381
    379382/**