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
This commit is contained in:
Felix Arntz 2019-01-16 14:05:00 +00:00
parent a6ec40d65d
commit 225f3055b8
2 changed files with 29 additions and 9 deletions

View File

@ -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 );
}

View File

@ -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.