Changeset 6158 for branches/0.9/bb-includes/wp-functions.php
- Timestamp:
- 12/12/2016 01:55:09 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/bb-includes/wp-functions.php
r2791 r6158 923 923 */ 924 924 if ( !function_exists('add_query_arg') ) : // [WP6064] 925 925 926 function add_query_arg() { 926 $ ret = '';927 if ( is_array( func_get_arg(0)) ) {928 if ( @func_num_args() < 2 || false === @func_get_arg(1))927 $args = func_get_args(); 928 if ( is_array( $args[0] ) ) { 929 if ( count( $args ) < 2 || false === $args[1] ) 929 930 $uri = $_SERVER['REQUEST_URI']; 930 931 else 931 $uri = @func_get_arg(1);932 $uri = $args[1]; 932 933 } else { 933 if ( @func_num_args() < 3 || false === @func_get_arg(2))934 if ( count( $args ) < 3 || false === $args[2] ) 934 935 $uri = $_SERVER['REQUEST_URI']; 935 936 else 936 $uri = @func_get_arg(2);937 } 938 939 if ( $frag = strstr( $uri, '#') )940 $uri = substr( $uri, 0, -strlen($frag));937 $uri = $args[2]; 938 } 939 940 if ( $frag = strstr( $uri, '#' ) ) 941 $uri = substr( $uri, 0, -strlen( $frag ) ); 941 942 else 942 943 $frag = ''; 943 944 944 if ( preg_match('|^https?://|i', $uri, $matches) ) { 945 $protocol = $matches[0]; 946 $uri = substr($uri, strlen($protocol)); 945 if ( 0 === stripos( $uri, 'http://' ) ) { 946 $protocol = 'http://'; 947 $uri = substr( $uri, 7 ); 948 } elseif ( 0 === stripos( $uri, 'https://' ) ) { 949 $protocol = 'https://'; 950 $uri = substr( $uri, 8 ); 947 951 } else { 948 952 $protocol = ''; 949 953 } 950 954 951 if (strpos($uri, '?') !== false) { 952 $parts = explode('?', $uri, 2); 953 if ( 1 == count($parts) ) { 954 $base = '?'; 955 $query = $parts[0]; 956 } else { 957 $base = $parts[0] . '?'; 958 $query = $parts[1]; 959 } 960 } elseif (!empty($protocol) || strpos($uri, '=') === false ) { 955 if ( strpos( $uri, '?' ) !== false ) { 956 list( $base, $query ) = explode( '?', $uri, 2 ); 957 $base .= '?'; 958 } elseif ( $protocol || strpos( $uri, '=' ) === false ) { 961 959 $base = $uri . '?'; 962 960 $query = ''; … … 966 964 } 967 965 968 wp_parse_str($query, $qs); 969 $qs = urlencode_deep($qs); // this re-URL-encodes things that were already in the query string 970 if ( is_array(func_get_arg(0)) ) { 971 $kayvees = func_get_arg(0); 972 $qs = array_merge($qs, $kayvees); 966 wp_parse_str( $query, $qs ); 967 $qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string 968 if ( is_array( $args[0] ) ) { 969 foreach ( $args[0] as $k => $v ) { 970 $qs[ $k ] = $v; 971 } 973 972 } else { 974 $qs[ func_get_arg(0)] = func_get_arg(1);973 $qs[ $args[0] ] = $args[1]; 975 974 } 976 975 977 976 foreach ( $qs as $k => $v ) { 978 977 if ( $v === false ) 979 unset( $qs[$k]);980 } 981 982 $ret = build_query( $qs);983 $ret = trim( $ret, '?');984 $ret = preg_replace( '#=(&|$)#', '$1', $ret);978 unset( $qs[$k] ); 979 } 980 981 $ret = build_query( $qs ); 982 $ret = trim( $ret, '?' ); 983 $ret = preg_replace( '#=(&|$)#', '$1', $ret ); 985 984 $ret = $protocol . $base . $ret . $frag; 986 $ret = rtrim( $ret, '?');985 $ret = rtrim( $ret, '?' ); 987 986 return $ret; 988 987 }
Note: See TracChangeset
for help on using the changeset viewer.