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.
Built from https://develop.svn.wordpress.org/trunk@46119


git-svn-id: http://core.svn.wordpress.org/trunk@45931 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-15 01:18:55 +00:00
parent 8988c1ce38
commit 142efedee0
2 changed files with 19 additions and 11 deletions

View File

@ -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(

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-46118';
$wp_version = '5.3-alpha-46119';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.