WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/26/2019 08:29:52 PM (22 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.

File:
1 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.
Note: See TracChangeset for help on using the changeset viewer.