wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_redirect_admin_locations › WordPress Function

Since3.4.0
Deprecatedn/a
› wp_redirect_admin_locations ( No parameters )
Defined at:
Codex:

Redirects a variety of shorthand URLs to the admin.

If a user visits example.com/admin, they'll be redirected to /wp-admin. Visiting /login redirects to /wp-login.php, and so on.


Source

function wp_redirect_admin_locations() {
	global $wp_rewrite;

	if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) {
		return;
	}

	$admins = array(
		home_url( 'wp-admin', 'relative' ),
		home_url( 'dashboard', 'relative' ),
		home_url( 'admin', 'relative' ),
		site_url( 'dashboard', 'relative' ),
		site_url( 'admin', 'relative' ),
	);

	if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins, true ) ) {
		wp_redirect( admin_url() );
		exit;
	}

	$logins = array(
		home_url( 'wp-login.php', 'relative' ),
		home_url( 'login.php', 'relative' ),
		home_url( 'login', 'relative' ),
		site_url( 'login', 'relative' ),
	);

	if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins, true ) ) {
		wp_redirect( wp_login_url() );
		exit;
	}

	/**
	 * Filters the well-known change password URL (/.well-known/change-password).
	 *
	 * By default visiting the well-known change password URL will redirect to
	 * the user's profile page when requested by a browser or password manager.
	 *
	 * Sites with a custom URL structure for modifying the passwords can modify
	 * the destination with this filter.
	 *
	 * The resulting URL is redirected using {@see wp_safe_redirect}, if the
	 * filtered URL is on an external host, that host will need to be included
	 * as an allowed host via the {@see 'allowed_redirect_hosts'} filter.
	 *
	 * @since 7.2.0
	 *
	 * @param string $change_password_url The URL to redirect to. Default is the user profile page.
	 */
	$change_password_url = apply_filters( 'wp_change_password_url', admin_url( 'profile.php' ) );

	/*
	 * The well-known change-password URL is always at the root of the origin
	 * per the spec (https://w3c.github.io/webappsec-change-password-url/), so
	 * only the root-relative path is matched here, regardless of whether
	 * WordPress is installed in a subdirectory.
	 */
	if (
		'/.well-known/change-password' === untrailingslashit( $_SERVER['REQUEST_URI'] )
		&& $change_password_url
		&& wp_safe_redirect( $change_password_url )
	) {
		exit;
	}
}