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
This commit is contained in:
Sergey Biryukov 2019-03-26 20:29:52 +00:00
parent a1cd087b6e
commit fb7c39f88d
2 changed files with 4 additions and 16 deletions

View File

@ -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.
}

View File

@ -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 );
}