From 317da56a3739f9730927a3109c6eb45efea72720 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 15 Sep 2019 01:17:24 +0000 Subject: [PATCH] Site Health: Show a more specific fatal error message when in Recovery Mode with headers already sent. Props garrett-eclipse, TimothyBlynJacobs, mukesh27, marybaum, afragen, Clorith, mdwolinski, SergeyBiryukov. Fixes #47321. git-svn-id: https://develop.svn.wordpress.org/trunk@46119 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-fatal-error-handler.php | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/class-wp-fatal-error-handler.php b/src/wp-includes/class-wp-fatal-error-handler.php index f17011cc33..d63e58d062 100644 --- a/src/wp-includes/class-wp-fatal-error-handler.php +++ b/src/wp-includes/class-wp-fatal-error-handler.php @@ -41,13 +41,15 @@ class WP_Fatal_Error_Handler { load_default_textdomain(); } + $handled = false; + if ( ! is_multisite() && wp_recovery_mode()->is_initialized() ) { - wp_recovery_mode()->handle_error( $error ); + $handled = wp_recovery_mode()->handle_error( $error ); } // Display the PHP error template if headers not sent. if ( is_admin() || ! headers_sent() ) { - $this->display_error_template( $error ); + $this->display_error_template( $error, $handled ); } } catch ( Exception $e ) { // Catch exceptions and remain silent. @@ -125,10 +127,12 @@ class WP_Fatal_Error_Handler { * If no such drop-in is available, this will call {@see WP_Fatal_Error_Handler::display_default_error_template()}. * * @since 5.2.0 + * @since 5.3.0 The `$handled` parameter was added. * - * @param array $error Error information retrieved from `error_get_last()`. + * @param array $error Error information retrieved from `error_get_last()`. + * @param true|WP_Error $handled Whether Recovery Mode handled the fatal error. */ - protected function display_error_template( $error ) { + protected function display_error_template( $error, $handled ) { if ( defined( 'WP_CONTENT_DIR' ) ) { // Load custom PHP error template, if present. $php_error_pluggable = WP_CONTENT_DIR . '/php-error.php'; @@ -140,7 +144,7 @@ class WP_Fatal_Error_Handler { } // Otherwise, display the default error template. - $this->display_default_error_template( $error ); + $this->display_default_error_template( $error, $handled ); } /** @@ -153,10 +157,12 @@ class WP_Fatal_Error_Handler { * be used to modify these parameters. * * @since 5.2.0 + * @since 5.3.0 The `$handled` parameter was added. * - * @param array $error Error information retrieved from `error_get_last()`. + * @param array $error Error information retrieved from `error_get_last()`. + * @param true|WP_Error $handled Whether Recovery Mode handled the fatal error. */ - protected function display_default_error_template( $error ) { + protected function display_default_error_template( $error, $handled ) { if ( ! function_exists( '__' ) ) { wp_load_translations_early(); } @@ -169,10 +175,12 @@ class WP_Fatal_Error_Handler { require_once ABSPATH . WPINC . '/class-wp-error.php'; } - if ( is_protected_endpoint() ) { - $message = __( 'The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.' ); + if ( true === $handled && wp_is_recovery_mode() ) { + $message = __( 'There has been a critical error on your website, putting it in recovery mode. Please check the Themes and Plugins screens for more details. If you just installed or updated a theme or plugin, check the relevant page for that first.' ); + } elseif ( is_protected_endpoint() ) { + $message = __( 'There has been a critical error on your website. Please check your site admin email inbox for instructions.' ); } else { - $message = __( 'The site is experiencing technical difficulties.' ); + $message = __( 'There has been a critical error on your website.' ); } $args = array(