WP_Recovery_Mode
Core class implementing Recovery Mode functionality. Orchestrates cookie, key, link, and email services.
Source: wp-includes/class-wp-recovery-mode.php
Since: 5.2.0
Constants
| Constant | Value | Description |
|---|---|---|
EXIT_ACTION |
'exit_recovery_mode' |
Login action for exiting recovery mode |
Properties
| Property | Type | Visibility | Description |
|---|---|---|---|
$cookie_service |
WP_Recovery_Mode_Cookie_Service | private | Handles cookie operations |
$key_service |
WP_Recovery_Mode_Key_Service | private | Generates recovery keys |
$link_service |
WP_Recovery_Mode_Link_Service | private | Generates and validates recovery links |
$email_service |
WP_Recovery_Mode_Email_Service | private | Sends recovery mode emails |
$is_initialized |
bool | private | Whether recovery mode has been initialized |
$is_active |
bool | private | Whether recovery mode is active in this session |
$session_id |
string | private | Current recovery mode session identifier |
Methods
__construct()
Creates a new recovery mode instance and initializes all services.
public function __construct()
Instantiates:
WP_Recovery_Mode_Cookie_ServiceWP_Recovery_Mode_Key_ServiceWP_Recovery_Mode_Link_ServiceWP_Recovery_Mode_Email_Service
initialize()
Initializes recovery mode for the current request.
public function initialize(): void
Actions Registered:
wp_logout→exit_recovery_mode()login_form_exit_recovery_mode→handle_exit_recovery_mode()recovery_mode_clean_expired_keys→clean_expired_keys()
Behavior:
- Schedules daily cron for
recovery_mode_clean_expired_keys - If
WP_RECOVERY_MODE_SESSION_IDis defined, activates recovery mode - If recovery cookie exists, validates and activates session
- Otherwise, checks for recovery mode link in URL
is_active()
Checks whether recovery mode is active.
public function is_active(): bool
Returns: true if recovery mode is active, false otherwise.
get_session_id()
Gets the recovery mode session ID.
public function get_session_id(): string
Returns: Session ID if active, empty string otherwise.
is_initialized()
Checks whether recovery mode has been initialized.
public function is_initialized(): bool
Returns: true if initialized, false otherwise.
handle_error()
Handles a fatal error occurring. The caller should die() after calling this.
public function handle_error( array $error ): true|WP_Error|void
| Parameter | Type | Description |
|---|---|---|
$error |
array | Error details from error_get_last() |
Returns:
trueif error handled and headers already sentvoidif redirecting to catch multiple errorsWP_Errorif error could not be handled
Error Codes:
invalid_source— Error not caused by plugin or themenon_protected_endpoint— Error on non-protected endpointstorage_error— Failed to store the error
Behavior:
- Identifies extension causing error
- Skips network-activated plugins in multisite
- If not in recovery mode, sends recovery email (if on protected endpoint)
- If in recovery mode, stores error and redirects
exit_recovery_mode()
Ends the current recovery mode session.
public function exit_recovery_mode(): bool
Returns: true on success, false if not active.
Actions:
- Clears email rate limit
- Clears recovery cookie
- Deletes all paused plugins
- Deletes all paused themes
handle_exit_recovery_mode()
Handles a request to exit recovery mode via login action.
public function handle_exit_recovery_mode(): void
URL Parameters:
action— Must beexit_recovery_mode_wpnonce— Valid nonce forexit_recovery_mode
Behavior:
- Verifies nonce
- Calls
exit_recovery_mode() - Redirects to referrer or admin/home
clean_expired_keys()
Removes expired recovery mode keys. Runs on daily cron.
public function clean_expired_keys(): void
handle_cookie() (protected)
Validates the recovery mode cookie and activates the session.
protected function handle_cookie(): void
Behavior:
- Validates cookie signature and expiration
- Extracts session ID from cookie
- Sets
$is_active = trueand$session_id - On error, clears cookie and calls
wp_die()
get_email_rate_limit() (protected)
Gets the rate limit between recovery mode emails.
protected function get_email_rate_limit(): int
Returns: Rate limit in seconds (default: DAY_IN_SECONDS).
Filter: recovery_mode_email_rate_limit
get_link_ttl() (protected)
Gets how long a recovery mode link is valid.
protected function get_link_ttl(): int
Returns: TTL in seconds (minimum of rate limit).
Filter: recovery_mode_email_link_ttl
get_extension_for_error() (protected)
Identifies the plugin or theme that caused the error.
protected function get_extension_for_error( array $error ): array|false
| Parameter | Type | Description |
|---|---|---|
$error |
array | Error details from error_get_last() |
Returns: Extension info array or false.
array(
'type' => 'plugin', // or 'theme'
'slug' => 'extension-directory-name',
)
is_network_plugin() (protected)
Checks if the extension is a network-activated plugin.
protected function is_network_plugin( array $extension ): bool
Returns: true if network plugin on multisite, false otherwise.
store_error() (protected)
Stores the error so the extension is paused.
protected function store_error( array $error ): bool
| Parameter | Type | Description |
|---|---|---|
$error |
array | Error details from error_get_last() |
Returns: true on success, false on failure.
redirect_protected() (protected)
Redirects the current request to catch multiple errors.
protected function redirect_protected(): void
Exits after redirect.