Allow redirect_canonical filter to cancel a redirect (just return FALSE). see #5766

git-svn-id: http://svn.automattic.com/wordpress/trunk@6743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2008-02-06 22:57:15 +00:00
parent 5b22db23d1
commit 302ac4890e
1 changed files with 16 additions and 13 deletions

View File

@ -187,22 +187,25 @@ function redirect_canonical($requested_url=null, $do_redirect=true) {
$redirect_url .= '?' . $redirect['query'];
}
if ( $redirect_url && $redirect_url != $requested_url ) {
// var_dump($redirect_url); die();
$redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url);
if ( $do_redirect) {
// protect against chained redirects
if ( !redirect_canonical($redirect_url, false) ) {
wp_redirect($redirect_url, 301);
exit();
} else {
return false;
}
if ( !$redirect_url || $redirect_url == $requested_url )
return false;
// Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE
$redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url);
if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request
return false;
if ( $do_redirect ) {
// protect against chained redirects
if ( !redirect_canonical($redirect_url, false) ) {
wp_redirect($redirect_url, 301);
exit();
} else {
return $redirect_url;
return false;
}
} else {
return false;
return $redirect_url;
}
}