From 9b0c765df63728ecc9c1a9f283d8562155ac0c78 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Tue, 31 Oct 2006 05:49:14 +0000 Subject: [PATCH] Better preservation of query string when using add_query_arg(). Props in self- and Andy-flavored varieties. fixes #3308 git-svn-id: http://svn.automattic.com/wordpress/trunk@4435 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 441a5043a8..513a5dd351 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -667,10 +667,13 @@ function add_query_arg() { } foreach($qs as $k => $v) { - if ( $v != '' ) { + if ( $v !== FALSE ) { if ( $ret != '' ) $ret .= '&'; - $ret .= "$k=$v"; + if ( empty($v) && !preg_match('|[?&]' . preg_quote($k, '|') . '=|', $query) ) + $ret .= $k; + else + $ret .= "$k=$v"; } } $ret = $protocol . $base . $ret . $frag; @@ -692,10 +695,10 @@ remove_query_arg(removekeyarray, [oldquery_or_uri]) function remove_query_arg($key, $query='') { if ( is_array($key) ) { // removing multiple keys foreach ( (array) $key as $k ) - $query = add_query_arg($k, '', $query); + $query = add_query_arg($k, FALSE, $query); return $query; } - return add_query_arg($key, '', $query); + return add_query_arg($key, FALSE, $query); } function add_magic_quotes($array) {