mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-31 13:37:51 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@43983 git-svn-id: http://core.svn.wordpress.org/trunk@43815 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2dce718157
commit
4b6b8a55fe
@ -349,7 +349,7 @@ function wp_debug_mode() {
|
||||
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
|
||||
}
|
||||
|
||||
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
|
||||
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
|
||||
@ini_set( 'display_errors', 0 );
|
||||
}
|
||||
}
|
||||
@ -1250,3 +1250,24 @@ function wp_finalize_scraping_edited_file_errors( $scrape_key ) {
|
||||
}
|
||||
echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether current request is a JSON request, or is expecting a JSON response.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
|
||||
*/
|
||||
function wp_is_json_request() {
|
||||
|
||||
if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.1-alpha-43982';
|
||||
$wp_version = '5.1-alpha-43983';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user