From fb7c39f88d61311a73755c4c592901e66286d4fd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 26 Mar 2019 20:29:52 +0000 Subject: [PATCH] Bootstrap/Load: Always run the fatal error handler at shutdown, but don't display the PHP error template once headers are sent. If a fatal error occurs midway through a page load, or in a REST API request, it still needs to be handled internally for the recovery mode, but the custom message may conflict with already rendered output, e.g. by displaying HTML markup in an XML or JSON request. Props spacedmonkey, flixos90, TimothyBlynJacobs. Fixes #45989. See #44458. git-svn-id: https://develop.svn.wordpress.org/trunk@45014 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-fatal-error-handler.php | 11 ++++------- src/wp-settings.php | 9 --------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/class-wp-fatal-error-handler.php b/src/wp-includes/class-wp-fatal-error-handler.php index e44dfed598..e469497af3 100644 --- a/src/wp-includes/class-wp-fatal-error-handler.php +++ b/src/wp-includes/class-wp-fatal-error-handler.php @@ -26,11 +26,6 @@ class WP_Fatal_Error_Handler { * @since 5.2.0 */ public function handle() { - // Bail if WordPress executed successfully. - if ( defined( 'WP_EXECUTION_SUCCEEDED' ) && WP_EXECUTION_SUCCEEDED ) { - return; - } - try { // Bail if no error found. $error = $this->detect_error(); @@ -42,8 +37,10 @@ class WP_Fatal_Error_Handler { wp_recovery_mode()->handle_error( $error ); } - // Display the PHP error template. - $this->display_error_template(); + // Display the PHP error template if headers not sent. + if ( ! headers_sent() ) { + $this->display_error_template(); + } } catch ( Exception $e ) { // Catch exceptions and remain silent. } diff --git a/src/wp-settings.php b/src/wp-settings.php index fa9f9a3a25..7b666e2851 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -544,12 +544,3 @@ if ( is_multisite() ) { * @since 3.0.0 */ do_action( 'wp_loaded' ); - -/* - * Store the fact that we could successfully execute the entire WordPress - * lifecycle. This is used to skip the premature shutdown handler, as it cannot - * be unregistered. - */ -if ( ! defined( 'WP_EXECUTION_SUCCEEDED' ) ) { - define( 'WP_EXECUTION_SUCCEEDED', true ); -}