Introducing wp_safe_redirect(). fixes #4606 for trunk

git-svn-id: https://develop.svn.wordpress.org/trunk@6131 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2007-09-18 22:23:16 +00:00
parent 7aabf7336f
commit 421356b6b8
3 changed files with 21 additions and 3 deletions

View File

@ -399,6 +399,24 @@ function wp_redirect($location, $status = 302) {
} }
endif; 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') ): if ( !function_exists('wp_get_cookie_login') ):
function wp_get_cookie_login() { function wp_get_cookie_login() {
if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ) if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) )

View File

@ -78,7 +78,7 @@ case 'logout' :
if ( isset( $_REQUEST['redirect_to'] ) ) if ( isset( $_REQUEST['redirect_to'] ) )
$redirect_to = $_REQUEST['redirect_to']; $redirect_to = $_REQUEST['redirect_to'];
wp_redirect($redirect_to); wp_safe_redirect($redirect_to);
exit(); exit();
break; break;
@ -324,7 +324,7 @@ default:
if ( !$using_cookie ) if ( !$using_cookie )
wp_setcookie($user_login, $user_pass, false, '', '', $rememberme); wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
do_action('wp_login', $user_login); do_action('wp_login', $user_login);
wp_redirect($redirect_to); wp_safe_redirect($redirect_to);
exit(); exit();
} else { } else {
if ( $using_cookie ) if ( $using_cookie )

View File

@ -7,5 +7,5 @@ if ( get_magic_quotes_gpc() )
// 10 days // 10 days
setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 864000, COOKIEPATH); setcookie('wp-postpass_' . COOKIEHASH, $_POST['post_password'], time() + 864000, COOKIEPATH);
wp_redirect(wp_get_referer()); wp_safe_redirect(wp_get_referer());
?> ?>