Make WordPress Core

Ticket #45940: 45940.diff

File 45940.diff, 2.1 KB (added by flixos90, 6 years ago)
  • src/wp-includes/class-wp-shutdown-handler.php

     
    3131                }
    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.
    4347                        $this->display_error_template();
     
    4751        }
    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() {
    5761                $error = error_get_last();
     
    5862
    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        }
    7292