From 302ac4890e38b7e9d802b3058adb1d37757e3a3e Mon Sep 17 00:00:00 2001 From: markjaquith Date: Wed, 6 Feb 2008 22:57:15 +0000 Subject: [PATCH] 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 --- wp-includes/canonical.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index c09031baa2..d500f695cb 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -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; } }