Preserve query string arrays in add_query_arg(). fixes #4878 for trunk
git-svn-id: https://develop.svn.wordpress.org/trunk@5999 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c6cef97007
commit
d5e3e96141
@ -98,18 +98,37 @@ if (!function_exists('array_change_key_case')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// From php.net
|
|
||||||
if (!function_exists('http_build_query')) {
|
if (!function_exists('http_build_query')) {
|
||||||
function http_build_query( $formdata, $numeric_prefix = null, $key = null ) {
|
function http_build_query($data, $prefix=null, $sep=null) {
|
||||||
$res = array();
|
return _http_build_query($data, $prefix, $sep);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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('_') ) {
|
if ( !function_exists('_') ) {
|
||||||
|
@ -645,16 +645,16 @@ function add_query_arg() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $qs as $k => $v ) {
|
foreach ( $qs as $k => $v ) {
|
||||||
if ( $v !== FALSE ) {
|
if ( $v === false )
|
||||||
if ( $ret != '' )
|
unset($qs[$k]);
|
||||||
$ret .= '&';
|
}
|
||||||
if ( empty($v) && !preg_match('|[?&]' . preg_quote($k, '|') . '=|', $query) )
|
|
||||||
$ret .= $k;
|
if ( ini_get('arg_separator.output') === '&')
|
||||||
|
$ret = http_build_query($qs, '', '&');
|
||||||
else
|
else
|
||||||
$ret .= "$k=$v";
|
$ret = _http_build_query($qs, NULL, '&');
|
||||||
}
|
|
||||||
}
|
|
||||||
$ret = trim($ret, '?');
|
$ret = trim($ret, '?');
|
||||||
|
$ret = preg_replace('#=(&|$)#', '$1', $ret);
|
||||||
$ret = $protocol . $base . $ret . $frag;
|
$ret = $protocol . $base . $ret . $frag;
|
||||||
$ret = rtrim($ret, '?');
|
$ret = rtrim($ret, '?');
|
||||||
return $ret;
|
return $ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user