From 225f3055b8d61b0f64b1b42046d70bcaf9c16e42 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Wed, 16 Jan 2019 14:05:00 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@44623 git-svn-id: http://core.svn.wordpress.org/trunk@44454 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-shutdown-handler.php | 36 ++++++++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/wp-includes/class-wp-shutdown-handler.php b/wp-includes/class-wp-shutdown-handler.php index 4761393757..dc887a5cd4 100644 --- a/wp-includes/class-wp-shutdown-handler.php +++ b/wp-includes/class-wp-shutdown-handler.php @@ -31,13 +31,17 @@ class WP_Shutdown_Handler { } try { - // Bail if no error found or if it could not be stored. - if ( ! $this->detect_error() ) { + // Bail if no error found. + $error = $this->detect_error(); + if ( ! $error ) { return; } - // Redirect the request to catch multiple errors in one go. - $this->redirect_protected(); + // If the error was stored and thus the extension paused, + // redirect the request to catch multiple errors in one go. + if ( $this->store_error( $error ) ) { + $this->redirect_protected(); + } // Display the PHP error template. $this->display_error_template(); @@ -47,26 +51,42 @@ class WP_Shutdown_Handler { } /** - * Detects the error causing the crash and stores it if one was found. + * Detects the error causing the crash if it should be handled. * * @since 5.1.0 * - * @return bool True if an error was found and stored, false otherwise. + * @return array|null Error that was triggered, or null if no error received or if the error should not be handled. */ protected function detect_error() { $error = error_get_last(); // No error, just skip the error handling code. if ( null === $error ) { - return false; + return null; } // Bail if this error should not be handled. if ( ! wp_should_handle_error( $error ) ) { + return null; + } + + return $error; + } + + /** + * Stores the given error so that the extension causing it is paused. + * + * @since 5.1.0 + * + * @param array $error Error that was triggered. + * @return bool True if the error was stored successfully, false otherwise. + */ + protected function store_error( $error ) { + // Do not pause extensions if they only crash on a non-protected endpoint. + if ( ! is_protected_endpoint() ) { return false; } - // Try to store the error so that the respective extension is paused. return wp_record_extension_error( $error ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 9e51b70726..1896671600 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta1-44622'; +$wp_version = '5.1-beta1-44623'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.