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


git-svn-id: http://core.svn.wordpress.org/trunk@44823 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2019-03-26 20:30:53 +00:00
parent 6b6201ed89
commit 3f6a9eb0e3
3 changed files with 5 additions and 17 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.
}