: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function wp_timezone_override_offset() {
$timezone_string = get_option( 'timezone_string' );
if ( ! $timezone_string ) {
$timezone_object = timezone_open( $timezone_string );
$datetime_object = date_create();
if ( false === $timezone_object || false === $datetime_object ) {
return round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 );
* Sort-helper for timezones.
function _wp_timezone_choice_usort_callback( $a, $b ) {
// Don't use translated versions of Etc.
if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {
// Make the order of these more like the old dropdown.
if ( str_starts_with( $a['city'], 'GMT+' ) && str_starts_with( $b['city'], 'GMT+' ) ) {
return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );
if ( 'UTC' === $a['city'] ) {
if ( str_starts_with( $b['city'], 'GMT+' ) ) {
if ( 'UTC' === $b['city'] ) {
if ( str_starts_with( $a['city'], 'GMT+' ) ) {
return strnatcasecmp( $a['city'], $b['city'] );
if ( $a['t_continent'] === $b['t_continent'] ) {
if ( $a['t_city'] === $b['t_city'] ) {
return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );
return strnatcasecmp( $a['t_city'], $b['t_city'] );
// Force Etc to the bottom of the list.
if ( 'Etc' === $a['continent'] ) {
if ( 'Etc' === $b['continent'] ) {
return strnatcasecmp( $a['t_continent'], $b['t_continent'] );
* Gives a nicely-formatted list of timezone strings.
* @since 4.7.0 Added the `$locale` parameter.
* @param string $selected_zone Selected timezone.
* @param string $locale Optional. Locale to load the timezones in. Default current site locale.
function wp_timezone_choice( $selected_zone, $locale = null ) {
static $mo_loaded = false, $locale_loaded = null;
$continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' );
// Load translations for continents and cities.
if ( ! $mo_loaded || $locale !== $locale_loaded ) {
$locale_loaded = $locale ? $locale : get_locale();
$mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
unload_textdomain( 'continents-cities', true );
load_textdomain( 'continents-cities', $mofile, $locale_loaded );
$tz_identifiers = timezone_identifiers_list();
foreach ( $tz_identifiers as $zone ) {
$zone = explode( '/', $zone );
if ( ! in_array( $zone[0], $continents, true ) ) {
// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later.
0 => ( isset( $zone[0] ) && $zone[0] ),
1 => ( isset( $zone[1] ) && $zone[1] ),
2 => ( isset( $zone[2] ) && $zone[2] ),
$exists[3] = ( $exists[0] && 'Etc' !== $zone[0] );
$exists[4] = ( $exists[1] && $exists[3] );
$exists[5] = ( $exists[2] && $exists[3] );
// phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
'continent' => ( $exists[0] ? $zone[0] : '' ),
'city' => ( $exists[1] ? $zone[1] : '' ),
'subcity' => ( $exists[2] ? $zone[2] : '' ),
't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ),
't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ),
't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ),
usort( $zonen, '_wp_timezone_choice_usort_callback' );
if ( empty( $selected_zone ) ) {
$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';
// If this is a deprecated, but valid, timezone string, display it at the top of the list as-is.
if ( in_array( $selected_zone, $tz_identifiers, true ) === false
&& in_array( $selected_zone, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true )
$structure[] = '<option selected="selected" value="' . esc_attr( $selected_zone ) . '">' . esc_html( $selected_zone ) . '</option>';
foreach ( $zonen as $key => $zone ) {
// Build value in an array to join later.
$value = array( $zone['continent'] );
if ( empty( $zone['city'] ) ) {
// It's at the continent level (generally won't happen).
$display = $zone['t_continent'];
// It's inside a continent group.
if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
$label = $zone['t_continent'];
$structure[] = '<optgroup label="' . esc_attr( $label ) . '">';
// Add the city to the value.
$value[] = $zone['city'];
$display = $zone['t_city'];
if ( ! empty( $zone['subcity'] ) ) {
// Add the subcity to the value.
$value[] = $zone['subcity'];
$display .= ' - ' . $zone['t_subcity'];
$value = implode( '/', $value );
if ( $value === $selected_zone ) {
$selected = 'selected="selected" ';
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $value ) . '">' . esc_html( $display ) . '</option>';
// Close continent optgroup.
if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) {
$structure[] = '</optgroup>';
$structure[] = '<optgroup label="' . esc_attr__( 'UTC' ) . '">';
if ( 'UTC' === $selected_zone ) {
$selected = 'selected="selected" ';
$structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __( 'UTC' ) . '</option>';
$structure[] = '</optgroup>';
// Do manual UTC offsets.
$structure[] = '<optgroup label="' . esc_attr__( 'Manual Offsets' ) . '">';
foreach ( $offset_range as $offset ) {
$offset_name = '+' . $offset;
$offset_name = (string) $offset;
$offset_value = $offset_name;
$offset_name = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $offset_name );
$offset_name = 'UTC' . $offset_name;
$offset_value = 'UTC' . $offset_value;
if ( $offset_value === $selected_zone ) {
$selected = 'selected="selected" ';
$structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . '</option>';
$structure[] = '</optgroup>';
return implode( "\n", $structure );
* Strips close comment and close php tags from file headers used by WP.
* @see https://core.trac.wordpress.org/ticket/8497
* @param string $str Header comment to clean up.
function _cleanup_header_comment( $str ) {
return trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $str ) );
* Permanently deletes comments or posts of any type that have held a status
* of 'trash' for the number of days defined in EMPTY_TRASH_DAYS.
* The default value of `EMPTY_TRASH_DAYS` is 30 (days).
* @global wpdb $wpdb WordPress database abstraction object.
function wp_scheduled_delete() {
$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
$posts_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );
foreach ( (array) $posts_to_delete as $post ) {
$post_id = (int) $post['post_id'];
$del_post = get_post( $post_id );
if ( ! $del_post || 'trash' !== $del_post->post_status ) {
delete_post_meta( $post_id, '_wp_trash_meta_status' );
delete_post_meta( $post_id, '_wp_trash_meta_time' );
wp_delete_post( $post_id );
$comments_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );
foreach ( (array) $comments_to_delete as $comment ) {
$comment_id = (int) $comment['comment_id'];
$del_comment = get_comment( $comment_id );
if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
delete_comment_meta( $comment_id, '_wp_trash_meta_time' );
delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
wp_delete_comment( $del_comment );
* Retrieves metadata from a file.
* Searches for metadata in the first 8 KB of a file, such as a plugin or theme.
* Each piece of metadata must be on its own line. Fields can not span multiple
* lines, the value will get cut at the end of the first line.
* If the file data is not within that first 8 KB, then the author should correct
* their plugin file and move the data headers to the top.
* @link https://codex.wordpress.org/File_Header
* @param string $file Absolute path to the file.
* @param array $default_headers List of headers, in the format `array( 'HeaderKey' => 'Header Name' )`.
* @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}.
* @return string[] Array of file header values keyed by header name.
function get_file_data( $file, $default_headers, $context = '' ) {
// Pull only the first 8 KB of the file in.
$file_data = file_get_contents( $file, false, null, 0, 8 * KB_IN_BYTES );
if ( false === $file_data ) {
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
* Filters extra file headers by context.
* The dynamic portion of the hook name, `$context`, refers to
* the context where extra headers might be loaded.
* @param array $extra_context_headers Empty array by default.
$extra_headers = $context ? apply_filters( "extra_{$context}_headers", array() ) : array();
$extra_headers = array_combine( $extra_headers, $extra_headers ); // Keys equal values.
$all_headers = array_merge( $extra_headers, (array) $default_headers );
$all_headers = $default_headers;
foreach ( $all_headers as $field => $regex ) {
if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
$all_headers[ $field ] = '';
* Useful for returning true to filters easily.
function __return_true() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
* Useful for returning false to filters easily.
function __return_false() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
* Useful for returning 0 to filters easily.
function __return_zero() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
* Returns an empty array.
* Useful for returning an empty array to filters easily.
* @return array Empty array.
function __return_empty_array() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
* Useful for returning null to filters easily.
* @return null Null value.
function __return_null() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
* Returns an empty string.
* Useful for returning an empty string to filters easily.
* @return string Empty string.
function __return_empty_string() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore
* Sends a HTTP header to disable content type sniffing in browsers which support it.
* @see https://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx
* @see https://src.chromium.org/viewvc/chrome?view=rev&revision=6985
function send_nosniff_header() {
header( 'X-Content-Type-Options: nosniff' );
* Returns a MySQL expression for selecting the week number based on the start_of_week option.