Make WordPress Core


Ignore:
Timestamp:
03/21/2019 09:52:07 PM (6 years ago)
Author:
flixos90
Message:

Bootstrap/Load: Introduce a recovery mode for fixing fatal errors.

Using the new fatal handler introduced in [44962], an email is sent to the admin when a fatal error occurs. This email includes a secret link to enter recovery mode. When clicked, the link will be validated and on success a cookie will be placed on the client, enabling recovery mode for that user. This functionality is executed early before plugins and themes are loaded, in order to be unaffected by potential fatal errors these might be causing.

When in recovery mode, broken plugins and themes will be paused for that client, so that they are able to access the admin backend despite of these errors. They are notified about the broken extensions and the errors caused, and can then decide whether they would like to temporarily deactivate the extension or fix the problem and resume the extension.

A link in the admin bar allows the client to exit recovery mode.

Props timothyblynjacobs, afragen, flixos90, nerrad, miss_jwo, schlessera, spacedmonkey, swissspidy.
Fixes #46130, #44458.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/error-protection.php

    r44962 r44973  
    66 * @since   5.2.0
    77 */
     8
     9/**
     10 * Get the instance for storing paused plugins.
     11 *
     12 * @return WP_Paused_Extensions_Storage
     13 */
     14function wp_paused_plugins() {
     15    static $storage = null;
     16
     17    if ( null === $storage ) {
     18        $storage = new WP_Paused_Extensions_Storage( 'plugin' );
     19    }
     20
     21    return $storage;
     22}
     23
     24/**
     25 * Get the instance for storing paused extensions.
     26 *
     27 * @return WP_Paused_Extensions_Storage
     28 */
     29function wp_paused_themes() {
     30    static $storage = null;
     31
     32    if ( null === $storage ) {
     33        $storage = new WP_Paused_Extensions_Storage( 'theme' );
     34    }
     35
     36    return $storage;
     37}
     38
     39/**
     40 * Get a human readable description of an extension's error.
     41 *
     42 * @since 5.2.0
     43 *
     44 * @param array $error Error details {@see error_get_last()}
     45 *
     46 * @return string Formatted error description.
     47 */
     48function wp_get_extension_error_description( $error ) {
     49    $constants   = get_defined_constants( true );
     50    $constants   = isset( $constants['Core'] ) ? $constants['Core'] : $constants['internal'];
     51    $core_errors = array();
     52
     53    foreach ( $constants as $constant => $value ) {
     54        if ( 0 === strpos( $constant, 'E_' ) ) {
     55            $core_errors[ $value ] = $constant;
     56        }
     57    }
     58
     59    if ( isset( $core_errors[ $error['type'] ] ) ) {
     60        $error['type'] = $core_errors[ $error['type'] ];
     61    }
     62
     63    /* translators: 1: error type, 2: error line number, 3: error file name, 4: error message */
     64    $error_message = __( 'An error of type %1$s was caused in line %2$s of the file %3$s. Error message: %4$s' );
     65
     66    return sprintf(
     67        $error_message,
     68        "<code>{$error['type']}</code>",
     69        "<code>{$error['line']}</code>",
     70        "<code>{$error['file']}</code>",
     71        "<code>{$error['message']}</code>"
     72    );
     73}
    874
    975/**
     
    53119    return apply_filters( 'wp_fatal_error_handler_enabled', $enabled );
    54120}
     121
     122/**
     123 * Access the WordPress Recovery Mode instance.
     124 *
     125 * @since 5.2.0
     126 *
     127 * @return WP_Recovery_Mode
     128 */
     129function wp_recovery_mode() {
     130    static $wp_recovery_mode;
     131
     132    if ( ! $wp_recovery_mode ) {
     133        $wp_recovery_mode = new WP_Recovery_Mode();
     134    }
     135
     136    return $wp_recovery_mode;
     137}
Note: See TracChangeset for help on using the changeset viewer.