: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
* @global string $currentday The day of the current post in the loop.
* @global string $previousday The day of the previous post in the loop.
* @return int 1 when new day, 0 if not a new day.
global $currentday, $previousday;
if ( $currentday !== $previousday ) {
* Builds URL query based on an associative and, or indexed array.
* This is a convenient function for easily building url queries. It sets the
* separator to '&' and uses _http_build_query() function.
* @see _http_build_query() Used to build the query
* @link https://www.php.net/manual/en/function.http-build-query.php for more on what
* http_build_query() does.
* @param array $data URL-encode key/value pairs.
* @return string URL-encoded string.
function build_query( $data ) {
return _http_build_query( $data, null, '&', '', false );
* From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
* @see https://www.php.net/manual/en/function.http-build-query.php
* @param array|object $data An array or object of data. Converted to array.
* @param string $prefix Optional. Numeric index. If set, start parameter numbering with it.
* @param string $sep Optional. Argument separator; defaults to 'arg_separator.output'.
* @param string $key Optional. Used to prefix key name. Default empty string.
* @param bool $urlencode Optional. Whether to use urlencode() in the result. Default true.
* @return string The query string.
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
foreach ( (array) $data as $k => $v ) {
if ( is_int( $k ) && null !== $prefix ) {
$k = $key . '%5B' . $k . '%5D';
} elseif ( false === $v ) {
if ( is_array( $v ) || is_object( $v ) ) {
array_push( $ret, _http_build_query( $v, '', $sep, $k, $urlencode ) );
} elseif ( $urlencode ) {
array_push( $ret, $k . '=' . urlencode( $v ) );
array_push( $ret, $k . '=' . $v );
$sep = ini_get( 'arg_separator.output' );
return implode( $sep, $ret );
* Retrieves a modified URL query string.
* You can rebuild the URL and append query variables to the URL query by using this function.
* There are two ways to use this function; either a single key and value, or an associative array.
* Using a single key and value:
* add_query_arg( 'key', 'value', 'http://example.com' );
* Using an associative array:
* ), 'http://example.com' );
* Omitting the URL from either use results in the current URL being used
* (the value of `$_SERVER['REQUEST_URI']`).
* Values are expected to be encoded appropriately with urlencode() or rawurlencode().
* Setting any query variable's value to boolean false removes the key (see remove_query_arg()).
* Important: The return value of add_query_arg() is not escaped by default. Output should be
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
* @since 5.3.0 Formalized the existing and already documented parameters
* by adding `...$args` to the function signature.
* @param string|array $key Either a query variable key, or an associative array of query variables.
* @param string $value Optional. Either a query variable value, or a URL to act upon.
* @param string $url Optional. A URL to act upon.
* @return string New URL query string (unescaped).
function add_query_arg( ...$args ) {
if ( is_array( $args[0] ) ) {
if ( count( $args ) < 2 || false === $args[1] ) {
$uri = $_SERVER['REQUEST_URI'];
if ( count( $args ) < 3 || false === $args[2] ) {
$uri = $_SERVER['REQUEST_URI'];
$frag = strstr( $uri, '#' );
$uri = substr( $uri, 0, -strlen( $frag ) );
if ( 0 === stripos( $uri, 'http://' ) ) {
$uri = substr( $uri, 7 );
} elseif ( 0 === stripos( $uri, 'https://' ) ) {
$uri = substr( $uri, 8 );
if ( str_contains( $uri, '?' ) ) {
list( $base, $query ) = explode( '?', $uri, 2 );
} elseif ( $protocol || ! str_contains( $uri, '=' ) ) {
wp_parse_str( $query, $qs );
$qs = urlencode_deep( $qs ); // This re-URL-encodes things that were already in the query string.
if ( is_array( $args[0] ) ) {
foreach ( $args[0] as $k => $v ) {
$qs[ $args[0] ] = $args[1];
foreach ( $qs as $k => $v ) {
$ret = build_query( $qs );
$ret = trim( $ret, '?' );
$ret = preg_replace( '#=(&|$)#', '$1', $ret );
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim( $ret, '?' );
$ret = str_replace( '?#', '#', $ret );
* Removes an item or items from a query string.
* Important: The return value of remove_query_arg() is not escaped by default. Output should be
* late-escaped with esc_url() or similar to help prevent vulnerability to cross-site scripting
* @param string|string[] $key Query key or keys to remove.
* @param false|string $query Optional. When false uses the current URL. Default false.
* @return string New URL query string.
function remove_query_arg( $key, $query = false ) {
if ( is_array( $key ) ) { // Removing multiple keys.
$query = add_query_arg( $k, false, $query );
return add_query_arg( $key, false, $query );
* Returns an array of single-use query variable names that can be removed from a URL.
* @return string[] An array of query variable names to remove from the URL.
function wp_removable_query_args() {
$removable_query_args = array(
'admin_email_remind_later',
'core-major-auto-updates-saved',
'hotkeys_highlight_first',
'hotkeys_highlight_last',
* Filters the list of query variable names to remove.
* @param string[] $removable_query_args An array of query variable names to remove from a URL.
return apply_filters( 'removable_query_args', $removable_query_args );
* Walks the array while sanitizing the contents.
* @since 5.5.0 Non-string values are left untouched.
* @param array $input_array Array to walk while sanitizing contents.
* @return array Sanitized $input_array.
function add_magic_quotes( $input_array ) {
foreach ( (array) $input_array as $k => $v ) {
$input_array[ $k ] = add_magic_quotes( $v );
} elseif ( is_string( $v ) ) {
$input_array[ $k ] = addslashes( $v );
* HTTP request for URI to retrieve content.
* @see wp_safe_remote_get()
* @param string $uri URI/URL of web page to retrieve.
* @return string|false HTTP content. False on failure.
function wp_remote_fopen( $uri ) {
$parsed_url = parse_url( $uri );
if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
$options['timeout'] = 10;
$response = wp_safe_remote_get( $uri, $options );
if ( is_wp_error( $response ) ) {
return wp_remote_retrieve_body( $response );
* Sets up the WordPress query.
* @global WP $wp Current WordPress environment instance.
* @global WP_Query $wp_query WordPress Query object.
* @global WP_Query $wp_the_query Copy of the WordPress Query object.
* @param string|array $query_vars Default WP_Query arguments.
function wp( $query_vars = '' ) {
global $wp, $wp_query, $wp_the_query;
$wp->main( $query_vars );
if ( ! isset( $wp_the_query ) ) {
$wp_the_query = $wp_query;
* Retrieves the description for the HTTP status.
* @since 3.9.0 Added status codes 418, 428, 429, 431, and 511.
* @since 4.5.0 Added status codes 308, 421, and 451.
* @since 5.1.0 Added status code 103.
* @since 6.6.0 Added status code 425.
* @global array $wp_header_to_desc
* @param int $code HTTP status code.
* @return string Status description if found, an empty string otherwise.
function get_status_header_desc( $code ) {
global $wp_header_to_desc;
if ( ! isset( $wp_header_to_desc ) ) {
$wp_header_to_desc = array(
101 => 'Switching Protocols',
203 => 'Non-Authoritative Information',
206 => 'Partial Content',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
402 => 'Payment Required',
405 => 'Method Not Allowed',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
421 => 'Misdirected Request',
422 => 'Unprocessable Entity',
424 => 'Failed Dependency',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
451 => 'Unavailable For Legal Reasons',
500 => 'Internal Server Error',
501 => 'Not Implemented',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
511 => 'Network Authentication Required',
if ( isset( $wp_header_to_desc[ $code ] ) ) {
return $wp_header_to_desc[ $code ];
* Sets HTTP status header.
* @since 4.4.0 Added the `$description` parameter.
* @see get_status_header_desc()
* @param int $code HTTP status code.
* @param string $description Optional. A custom description for the HTTP status.
* Defaults to the result of get_status_header_desc() for the given code.
function status_header( $code, $description = '' ) {
$description = get_status_header_desc( $code );
if ( empty( $description ) ) {
$protocol = wp_get_server_protocol();
$status_header = "$protocol $code $description";
if ( function_exists( 'apply_filters' ) ) {
* Filters an HTTP status header.
* @param string $status_header HTTP status header.
* @param int $code HTTP status code.
* @param string $description Description for the status code.
* @param string $protocol Server protocol.
$status_header = apply_filters( 'status_header', $status_header, $code, $description, $protocol );
if ( ! headers_sent() ) {
header( $status_header, true, $code );
* Gets the HTTP header information to prevent caching.
* The several different headers cover the different ways cache prevention
* is handled by different browsers.
* @since 6.3.0 The `Cache-Control` header for logged in users now includes the
* `no-store` and `private` directives.
* @return array The associative array of header names and field values.
function wp_get_nocache_headers() {
$cache_control = ( function_exists( 'is_user_logged_in' ) && is_user_logged_in() )
? 'no-cache, must-revalidate, max-age=0, no-store, private'
: 'no-cache, must-revalidate, max-age=0';
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',