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. git-svn-id: https://develop.svn.wordpress.org/trunk@44623 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
72e86aacfb
commit
33f524f9c2
@ -31,13 +31,17 @@ class WP_Shutdown_Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Bail if no error found or if it could not be stored.
|
// Bail if no error found.
|
||||||
if ( ! $this->detect_error() ) {
|
$error = $this->detect_error();
|
||||||
|
if ( ! $error ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect the request to catch multiple errors in one go.
|
// If the error was stored and thus the extension paused,
|
||||||
$this->redirect_protected();
|
// redirect the request to catch multiple errors in one go.
|
||||||
|
if ( $this->store_error( $error ) ) {
|
||||||
|
$this->redirect_protected();
|
||||||
|
}
|
||||||
|
|
||||||
// Display the PHP error template.
|
// Display the PHP error template.
|
||||||
$this->display_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
|
* @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() {
|
protected function detect_error() {
|
||||||
$error = error_get_last();
|
$error = error_get_last();
|
||||||
|
|
||||||
// No error, just skip the error handling code.
|
// No error, just skip the error handling code.
|
||||||
if ( null === $error ) {
|
if ( null === $error ) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bail if this error should not be handled.
|
// Bail if this error should not be handled.
|
||||||
if ( ! wp_should_handle_error( $error ) ) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to store the error so that the respective extension is paused.
|
|
||||||
return wp_record_extension_error( $error );
|
return wp_record_extension_error( $error );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user