WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp safe redirect

Description

Performs a safe (local) redirect, using wp_redirect().

Checks whether the $location is using an allowed host, if it has an absolute path. A plugin can therefore set or remove allowed host(s) to or from the list.

If the host is not allowed, then the redirect is to wp-admin on the siteurl instead. This prevents malicious redirects which redirect to another host, but only used in a few places.

The list of safe hosts can be hooked into via the allowed_redirect_hosts filter.

Usage

wp_safe_redirect() does not exit automatically and should almost always be followed by exit.

<?php
wp_safe_redirect( $location, $status );
exit;
?>

Parameters

$location
(string) (required)
Default: None
$status
(integer) (optional)
Default: 302

Return Values

(void) 
Does not return anything

Change Log

Since: 2.3

Source File

wp_safe_redirect() is located in wp-includes/pluggable.php

Related

See also index of Function Reference and index of Template Tags.