WP_Recovery_Mode::handle_error( array $error ): true|WP_Error
- Since
- 5.2.0
- Source
wp-includes/class-wp-recovery-mode.php:168
Description
The calling API should immediately die() after calling this function.
Compatibility
- WordPress
- since 5.2.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$errorarray- Error details from
error_get_last().
Return value
true|WP_Error- True if the error was handled and headers have already been sent.
Or the request will exit to try and catch multiple errors at once.
WP_Error if an error occurred preventing it from being handled.
Performance profile
How much work a call to WP_Recovery_Mode::handle_error() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 14–34
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 69.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Recovery_Mode::handle_error()
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Recovery_Mode::handle_error() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14 | ->get_extension_for_error(), __() |
->is_network_plugin() | 18 | ->get_extension_for_error(), ->is_network_plugin(), __() |
!->is_network_plugin() && ->is_active() && ->store_error() && headers_sent() | 21 | ->get_extension_for_error(), ->is_network_plugin(), ->is_active(), ->store_error(), headers_sent() |
!->is_network_plugin() && ->is_active() && ->store_error() && !headers_sent() | 23 | ->get_extension_for_error(), ->is_network_plugin(), ->is_active(), ->store_error(), headers_sent(), ->redirect_protected() |
!->is_network_plugin() && !->is_active() && !is_protected_endpoint() | 24 | ->get_extension_for_error(), ->is_network_plugin(), ->is_active(), is_protected_endpoint(), __() |
!->is_network_plugin() && ->is_active() && !->store_error() | 25 | ->get_extension_for_error(), ->is_network_plugin(), ->is_active(), ->store_error(), __() |
!->is_network_plugin() && !->is_active() && is_protected_endpoint() | 29–34 | ->get_extension_for_error(), ->is_network_plugin(), ->is_active(), is_protected_endpoint(), function_exists(), ->get_email_rate_limit(), ->maybe_send_recovery_mode_email() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 69 instructions, 14–34 executed per call, 7 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 9
- __()Retrieves the translation of $text.
- is_protected_endpoint()Determines whether we are currently on an endpoint that should be protected against WSODs.
- WP_Recovery_Mode::get_extension_for_error()Gets the extension that the error occurred in.
- WP_Recovery_Mode::is_network_plugin()Checks whether the given extension a network activated plugin.
- WP_Error::__construct()Initializes the error.
- WP_Recovery_Mode::is_active()Checks whether recovery mode is active.
- WP_Recovery_Mode::get_email_rate_limit()Gets the rate limit between sending new recovery mode email links.
- WP_Recovery_Mode::store_error()Stores the given error so that the extension causing it is paused.
- WP_Recovery_Mode::redirect_protected()Redirects the current request to allow recovering multiple errors in one go.
Source code
public function handle_error( array $error ) { $extension = $this->get_extension_for_error( $error ); if ( ! $extension || $this->is_network_plugin( $extension ) ) { return new WP_Error( 'invalid_source', __( 'Error not caused by a plugin or theme.' ) ); } if ( ! $this->is_active() ) { if ( ! is_protected_endpoint() ) { return new WP_Error( 'non_protected_endpoint', __( 'Error occurred on a non-protected endpoint.' ) ); } if ( ! function_exists( 'wp_generate_password' ) ) { require_once ABSPATH . WPINC . '/pluggable.php'; } return $this->email_service->maybe_send_recovery_mode_email( $this->get_email_rate_limit(), $error, $extension ); } if ( ! $this->store_error( $error ) ) { return new WP_Error( 'storage_error', __( 'Failed to store the error.' ) ); } if ( headers_sent() ) { return true; } $this->redirect_protected(); }Changelog
Introduced in 5.2.0. 2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
true|WP_Error|void to true|WP_Error.verified against sourcetrue|WP_Error to true|WP_Error|void.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-recovery-mode.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.