Make WordPress Core


Ignore:
Timestamp:
01/16/2019 02:03:35 PM (6 years ago)
Author:
flixos90
Message:

Bootstrap/Load: Only pause extensions when they cause a crash on a protected endpoint.

This is a first step on pausing extensions less aggressively. If a plugin or theme only causes a crash in the frontend, there is no point in pausing it in the admin backend.

See #45940, #44458.

File:
1 edited

Legend:

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

    r44622 r44623  
    3232
    3333        try {
    34             // Bail if no error found or if it could not be stored.
    35             if ( ! $this->detect_error() ) {
     34            // Bail if no error found.
     35            $error = $this->detect_error();
     36            if ( ! $error ) {
    3637                return;
    3738            }
    3839
    39             // Redirect the request to catch multiple errors in one go.
    40             $this->redirect_protected();
     40            // If the error was stored and thus the extension paused,
     41            // redirect the request to catch multiple errors in one go.
     42            if ( $this->store_error( $error ) ) {
     43                $this->redirect_protected();
     44            }
    4145
    4246            // Display the PHP error template.
     
    4852
    4953    /**
    50      * Detects the error causing the crash and stores it if one was found.
     54     * Detects the error causing the crash if it should be handled.
    5155     *
    5256     * @since 5.1.0
    5357     *
    54      * @return bool True if an error was found and stored, false otherwise.
     58     * @return array|null Error that was triggered, or null if no error received or if the error should not be handled.
    5559     */
    5660    protected function detect_error() {
     
    5963        // No error, just skip the error handling code.
    6064        if ( null === $error ) {
    61             return false;
     65            return null;
    6266        }
    6367
    6468        // Bail if this error should not be handled.
    6569        if ( ! wp_should_handle_error( $error ) ) {
     70            return null;
     71        }
     72
     73        return $error;
     74    }
     75
     76    /**
     77     * Stores the given error so that the extension causing it is paused.
     78     *
     79     * @since 5.1.0
     80     *
     81     * @param array $error Error that was triggered.
     82     * @return bool True if the error was stored successfully, false otherwise.
     83     */
     84    protected function store_error( $error ) {
     85        // Do not pause extensions if they only crash on a non-protected endpoint.
     86        if ( ! is_protected_endpoint() ) {
    6687            return false;
    6788        }
    6889
    69         // Try to store the error so that the respective extension is paused.
    7090        return wp_record_extension_error( $error );
    7191    }
Note: See TracChangeset for help on using the changeset viewer.