WordPress.org

Make WordPress Core

Changeset 43983


Ignore:
Timestamp:
12/12/2018 03:07:58 AM (13 months ago)
Author:
jeremyfelt
Message:

Load: Disable PHP errors for JSON requests

Because WP REST API requests aren't identified until parse_request, it's impractical to reference the REST_REQUEST constant in wp_debug_mode(). Instead, it's more helpful to assume that a request wanting a JSON response probably doesn't want PHP errors breaking the response.

Merges [43730] to trunk.

Props chrisl27, duanestorey, earnjam.
Fixes #44534.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/load.php

    r43571 r43983  
    350350    }
    351351
    352     if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
     352    if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
    353353        @ini_set( 'display_errors', 0 );
    354354    }
     
    12511251    echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
    12521252}
     1253
     1254/**
     1255 * Checks whether current request is a JSON request, or is expecting a JSON response.
     1256 *
     1257 * @since 5.0.0
     1258 *
     1259 * @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
     1260 */
     1261function wp_is_json_request() {
     1262
     1263    if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
     1264        return true;
     1265    }
     1266
     1267    if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
     1268        return true;
     1269    }
     1270
     1271    return false;
     1272
     1273}
Note: See TracChangeset for help on using the changeset viewer.