WP_Recovery_Mode::redirect_protected() WordPress Method

WP_Recovery_Mode::redirect_protected() is a method used to protect WordPress from being accessed by unauthorized users. By default, this method will redirect any user who is not logged in to the WordPress login page. However, you can customize this behavior by specifying a different URL to redirect to in the $redirect_url parameter.

WP_Recovery_Mode::redirect_protected() #

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.


Top ↑

Source

File: wp-includes/class-wp-recovery-mode.php

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


Top ↑

Changelog

Changelog
VersionDescription
5.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.