WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/09/2019 08:04:55 PM (7 months ago)
Author:
flixos90
Message:

Bootstrap/Load: Introduce fatal error recovery mechanism allowing users to still log in to their admin dashboard.

This changeset introduces a WP_Shutdown_Handler class that detects fatal errors and which extension (plugin or theme) causes them. Such an error is then recorded, and an error message is displayed. Subsequently, in certain protected areas, for example the admin, the broken extension will be paused, ensuring that the website is still usable in the respective area. The major benefit is that this mechanism allows site owners to still log in to their website, to fix the problem by either disabling the extension or solving the bug and then resuming the extension.

Extensions are only paused in certain designated areas. The frontend for example stays unaffected, as it is impossible to know what pausing the extension would cause to be missing, so it might be preferrable to clearly see that the website is temporarily not accessible instead.

The fatal error recovery is especially important in scope of encouraging the switch to a maintained PHP version, as not necessarily every WordPress extension is compatible with all PHP versions. If problems occur now, non-technical site owners that do not have immediate access to the codebase are not locked out of their site and can at least temporarily solve the problem quickly.

Websites that have custom requirements in that regard can implement their own shutdown handler by adding a shutdown-handler.php drop-in that returns the handler instance to use, which must be based on a class that inherits WP_Shutdown_Handler. That handler will then be used in place of the default one.

Websites that would like to modify specifically the error template displayed in the frontend can add a php-error.php drop-in that works similarly to the existing db-error.php drop-in.

Props afragen, bradleyt, flixos90, ocean90, schlessera, SergeyBiryukov, spacedmonkey.
Fixes #44458.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-settings.php

    r44344 r44524  
    1818// Include files required for initialization.
    1919require( ABSPATH . WPINC . '/load.php' );
     20require( ABSPATH . WPINC . '/class-wp-paused-extensions-storage.php' );
     21require( ABSPATH . WPINC . '/class-wp-shutdown-handler.php' );
     22require( ABSPATH . WPINC . '/error-protection.php' );
    2023require( ABSPATH . WPINC . '/default-constants.php' );
    2124require_once( ABSPATH . WPINC . '/plugin.php' );
     25
     26// Make sure we register the premature shutdown handler as soon as possible.
     27wp_register_premature_shutdown_handler();
    2228
    2329/*
     
    475481
    476482// Load the functions for the active theme, for both parent and child theme if applicable.
    477 if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
    478     if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) ) {
    479         include( STYLESHEETPATH . '/functions.php' );
     483foreach ( wp_get_active_and_valid_themes() as $theme ) {
     484    if ( file_exists( $theme . '/functions.php' ) ) {
     485        include $theme . '/functions.php';
    480486    }
    481     if ( file_exists( TEMPLATEPATH . '/functions.php' ) ) {
    482         include( TEMPLATEPATH . '/functions.php' );
    483     }
    484 }
     487}
     488unset( $theme );
    485489
    486490/**
     
    527531 */
    528532do_action( 'wp_loaded' );
     533
     534/*
     535 * Store the fact that we could successfully execute the entire WordPress
     536 * lifecycle. This is used to skip the premature shutdown handler, as it cannot
     537 * be unregistered.
     538 */
     539if ( ! defined( 'WP_EXECUTION_SUCCEEDED' ) ) {
     540    define( 'WP_EXECUTION_SUCCEEDED', true );
     541}
Note: See TracChangeset for help on using the changeset viewer.