Only urlencode previously existing values in add_query_arg() (more backwards compatible). fixes #4935. see #4084. see #4878

git-svn-id: https://develop.svn.wordpress.org/trunk@6064 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith
2007-09-08 14:27:24 +00:00
parent 41be365adf
commit ed03cc32dc
2 changed files with 21 additions and 10 deletions

View File

@@ -105,25 +105,34 @@ if (!function_exists('http_build_query')) {
}
// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
function _http_build_query($data, $prefix=null, $sep=null, $key='') {
function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true) {
$ret = array();
if ( $urlencode ) {
$lsb = '%5B';
$rsb = '%5D';
} else {
$lsb = '[';
$rsb = ']';
}
foreach ( (array) $data as $k => $v ) {
$k = urlencode($k);
if ( $urlencode)
$k = urlencode($k);
if ( is_int($k) && $prefix != null )
$k = $prefix.$k;
if ( !empty($key) )
$k = $key . '%5B' . $k . '%5D';
if ( $v === NULL )
continue;
elseif ( $v === FALSE )
$v = '0';
if ( is_array($v) || is_object($v) )
array_push($ret,_http_build_query($v, '', $sep, $k));
else
array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
elseif ( $urlencode )
array_push($ret, $k.'='.urlencode($v));
}
else
array_push($ret, $k.'='.$v);
}
if ( NULL === $sep )
$sep = ini_get('arg_separator.output');