| 835 | * Gets an item or items from a query string. |
| 836 | * |
| 837 | * @since 4.8.0 |
| 838 | * |
| 839 | * @param string|array $key Query key or keys to get. |
| 840 | * @param bool|string $query Optional. When false uses the current URL. Default false. |
| 841 | * @return string|null|array Value for the key or null, or an associative array of keys and |
| 842 | * their values if $key is an array. |
| 843 | */ |
| 844 | function get_query_arg( $key, $query = false ) { |
| 845 | if ( false === $query ) { |
| 846 | $query = $_SERVER['REQUEST_URI']; |
| 847 | } |
| 848 | |
| 849 | $query_string = parse_url( $query, PHP_URL_QUERY ); |
| 850 | if ( ! $query_string ) { |
| 851 | if ( is_array( $key ) ) { |
| 852 | return array_combine( $key, array_fill( 0, count( $key ), null ) ); |
| 853 | } |
| 854 | |
| 855 | return null; |
| 856 | } |
| 857 | |
| 858 | parse_str( $query_string, $query_args ); |
| 859 | |
| 860 | if ( is_array( $key ) ) { |
| 861 | $results = array(); |
| 862 | |
| 863 | foreach ( $key as $k ) { |
| 864 | if ( isset( $query_args[ $k ] ) ) { |
| 865 | $results[ $k ] = $query_args[ $k ]; |
| 866 | } else { |
| 867 | $results[ $k ] = null; |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | return $results; |
| 872 | } |
| 873 | |
| 874 | if ( ! isset( $query_args[ $key ] ) ) { |
| 875 | return null; |
| 876 | } |
| 877 | |
| 878 | return $query_args[ $key ]; |
| 879 | } |
| 880 | |
| 881 | /** |