Preserve query string arrays in add_query_arg(). fixes #4878 for trunk
git-svn-id: http://svn.automattic.com/wordpress/trunk@5999 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
93840b1632
commit
0906863d2c
|
@ -98,18 +98,37 @@ if (!function_exists('array_change_key_case')) {
|
|||
}
|
||||
}
|
||||
|
||||
// From php.net
|
||||
if(!function_exists('http_build_query')) {
|
||||
function http_build_query( $formdata, $numeric_prefix = null, $key = null ) {
|
||||
$res = array();
|
||||
foreach ((array)$formdata as $k=>$v) {
|
||||
$tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k);
|
||||
if ($key) $tmp_key = $key.'['.$tmp_key.']';
|
||||
$res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) );
|
||||
}
|
||||
$separator = ini_get('arg_separator.output');
|
||||
return implode($separator, $res);
|
||||
}
|
||||
if (!function_exists('http_build_query')) {
|
||||
function http_build_query($data, $prefix=null, $sep=null) {
|
||||
return _http_build_query($data, $prefix, $sep);
|
||||
}
|
||||
}
|
||||
|
||||
// from php.net (modified by Mark Jaquith to behave like the native PHP5 function)
|
||||
function _http_build_query($data, $prefix=null, $sep=null, $key='') {
|
||||
$ret = array();
|
||||
foreach ( (array) $data as $k => $v ) {
|
||||
$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, $k.'='.urlencode($v));
|
||||
}
|
||||
|
||||
if ( NULL === $sep )
|
||||
$sep = ini_get('arg_separator.output');
|
||||
|
||||
return implode($sep, $ret);
|
||||
}
|
||||
|
||||
if ( !function_exists('_') ) {
|
||||
|
|
|
@ -644,17 +644,17 @@ function add_query_arg() {
|
|||
$qs[func_get_arg(0)] = func_get_arg(1);
|
||||
}
|
||||
|
||||
foreach($qs as $k => $v) {
|
||||
if ( $v !== FALSE ) {
|
||||
if ( $ret != '' )
|
||||
$ret .= '&';
|
||||
if ( empty($v) && !preg_match('|[?&]' . preg_quote($k, '|') . '=|', $query) )
|
||||
$ret .= $k;
|
||||
else
|
||||
$ret .= "$k=$v";
|
||||
}
|
||||
foreach ( $qs as $k => $v ) {
|
||||
if ( $v === false )
|
||||
unset($qs[$k]);
|
||||
}
|
||||
|
||||
if ( ini_get('arg_separator.output') === '&')
|
||||
$ret = http_build_query($qs, '', '&');
|
||||
else
|
||||
$ret = _http_build_query($qs, NULL, '&');
|
||||
$ret = trim($ret, '?');
|
||||
$ret = preg_replace('#=(&|$)#', '$1', $ret);
|
||||
$ret = $protocol . $base . $ret . $frag;
|
||||
$ret = rtrim($ret, '?');
|
||||
return $ret;
|
||||
|
|
Loading…
Reference in New Issue