Skip to content

Commit

Permalink
Introducing wp_safe_redirect(). fixes #4606 for trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.automattic.com/wordpress/trunk@6131 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
markjaquith committed Sep 18, 2007
1 parent bbe284b commit dbd3d07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,24 @@ function wp_redirect($location, $status = 302) {
}
endif;

if ( !function_exists('wp_safe_redirect') ) :
/**
* performs a safe (local) redirect, using wp_redirect()
* @return void
**/
function wp_safe_redirect($location, $status = 302) {
if ( $location{0} == '/' ) {
if ( $location{1} == '/' )
$location = get_option('home') . '/';
} else {
if ( substr($location, 0, strlen(get_option('home'))) != get_option('home') )
$location = get_option('home') . '/';
}

wp_redirect($location, $status);
}
endif;

if ( !function_exists('wp_get_cookie_login') ):
function wp_get_cookie_login() {
if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )
Expand Down
4 changes: 2 additions & 2 deletions wp-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function focusit() {
if ( isset( $_REQUEST['redirect_to'] ) )
$redirect_to = $_REQUEST['redirect_to'];

wp_redirect($redirect_to);
wp_safe_redirect($redirect_to);
exit();

break;
Expand Down Expand Up @@ -324,7 +324,7 @@ function focusit() {
if ( !$using_cookie )
wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
do_action('wp_login', $user_login);
wp_redirect($redirect_to);
wp_safe_redirect($redirect_to);
exit();
} else {
if ( $using_cookie )
Expand Down
2 changes: 1 addition & 1 deletion wp-pass.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
// 10 days
setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 864000, COOKIEPATH);

wp_redirect(wp_get_referer());
wp_safe_redirect(wp_get_referer());
?>

0 comments on commit dbd3d07

Please sign in to comment.