Make WordPress Core

09/20/2022 12:41:58 AM (20 months ago)

Date/Time: Correct sanitization of localized default timezone_string in populate_options().

This fixes a bug where if the default timezone_string is set to a deprecated timezone name due to a localization providing an outdated timezone name string, this localized timezone string would be discarded and an empty string would be set as the timezone value instead.

By passing the DateTimeZone::ALL_WITH_BC constant as the $timezoneGroup parameter to the PHP native timezone_identifiers_list() function, a timezone name list is retrieved containing both current and deprecated timezone names, preventing the invalidation of the option value.

See the extensive write-up about this in ticket #56468.

Also see: PHP Manual: timezone_identifiers_list().


  • Expanding the translators comment to encourage translators to use “old” names over “new” names.
  • Adding a dedicated test to the Tests_Admin_IncludesSchema test class.

Follow-up to [54207], [54217], [54227], [54229], [54230].

Props jrf, costdev.
See #56468.

1 edited


  • trunk/src/wp-admin/includes/schema.php

    r53815 r54232  
    389389     * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14)
    390390     * or a valid timezone string (America/New_York). See
    391      * for all timezone strings supported by PHP.
     391     * for all timezone strings currently supported by PHP.
     392     *
     393     * Important: When a previous timezone string, like `Europe/Kiev`, has been superseded by an
     394     * updated one, like `Europe/Kyiv`, as a rule of thumb, the **old** timezone name should be used
     395     * in the "translation" to allow for the default timezone setting to be PHP cross-version compatible,
     396     * as old timezone names will be recognized in new PHP versions, while new timezone names cannot
     397     * be recognized in old PHP versions.
     398     *
     399     * To verify which timezone strings are available in the _oldest_ PHP version supported, you can
     400     * use and replace the "BR" (Brazil) in the code line with the
     401     * country code for which you want to look up the supported timezone names.
    392402     */
    393403    $offset_or_tz = _x( '0', 'default GMT offset or timezone string' );
    394404    if ( is_numeric( $offset_or_tz ) ) {
    395405        $gmt_offset = $offset_or_tz;
    396     } elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list(), true ) ) {
    397             $timezone_string = $offset_or_tz;
     406    } elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) {
     407        $timezone_string = $offset_or_tz;
    398408    }
Note: See TracChangeset for help on using the changeset viewer.