WordPress.org

Make WordPress Core

Changeset 45014


Ignore:
Timestamp:
03/26/2019 08:29:52 PM (7 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-fatal-error-handler.php

    r44973 r45014  
    2727     */
    2828    public function handle() {
    29         // Bail if WordPress executed successfully.
    30         if ( defined( 'WP_EXECUTION_SUCCEEDED' ) && WP_EXECUTION_SUCCEEDED ) {
    31             return;
    32         }
    33 
    3429        try {
    3530            // Bail if no error found.
     
    4338            }
    4439
    45             // Display the PHP error template.
    46             $this->display_error_template();
     40            // Display the PHP error template if headers not sent.
     41            if ( ! headers_sent() ) {
     42                $this->display_error_template();
     43            }
    4744        } catch ( Exception $e ) {
    4845            // Catch exceptions and remain silent.
  • trunk/src/wp-settings.php

    r44973 r45014  
    545545 */
    546546do_action( 'wp_loaded' );
    547 
    548 /*
    549  * Store the fact that we could successfully execute the entire WordPress
    550  * lifecycle. This is used to skip the premature shutdown handler, as it cannot
    551  * be unregistered.
    552  */
    553 if ( ! defined( 'WP_EXECUTION_SUCCEEDED' ) ) {
    554     define( 'WP_EXECUTION_SUCCEEDED', true );
    555 }
Note: See TracChangeset for help on using the changeset viewer.