wppaste
WordPress

WP_Recovery_Mode::redirect_protected()

Since
5.2.0
Source
wp-includes/class-wp-recovery-mode.php:459
Redirects the current request to allow recovering multiple errors in one go.

Description

The redirection will only happen when on a protected endpoint.

It must be ensured that this method is only called when an error actually occurred and will not occur on the next request again. Otherwise it will create a redirect loop.

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.

Performance profile

How much work a call to WP_Recovery_Mode::redirect_protected() 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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
23–29

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 30.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()one call below WP_Recovery_Mode::redirect_protected()

Further down the call graph this can also reach option, cache, serialize, query 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 · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Recovery_Mode::redirect_protected() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always23–29function_exists(), is_ssl(), wp_safe_redirect(), exit()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev3023–292
8.53023–292
8.43023–2922 more instructions than PHP 8.3
8.32821–272
8.22821–272
8.12821–272
7.42821–272

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 · 2

Used by · 1

Source code

	protected function redirect_protected() {		// Pluggable is usually loaded after plugins, so we manually include it here for redirection functionality.		if ( ! function_exists( 'wp_safe_redirect' ) ) {			require_once ABSPATH . WPINC . '/pluggable.php';		} 		$scheme = is_ssl() ? 'https://' : 'http://'; 		$url = "{$scheme}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";		wp_safe_redirect( $url );		exit;	}

Changelog

Introduced in 5.2.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Return type changed from none to never.verified against source
5.2.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.