From 3d18a0c26445137b380f2859dbc83d73bc7f3a38 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 20 Sep 2022 00:43:09 +0000 Subject: [PATCH] Date/Time: Correct sanitization of localized default `timezone_string` in `populate_options()`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: [https://www.php.net/manual/en/datetimezone.listidentifiers.php PHP Manual: timezone_identifiers_list()]. Includes: * 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. Built from https://develop.svn.wordpress.org/trunk@54232 git-svn-id: http://core.svn.wordpress.org/trunk@53791 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/schema.php | 16 +++++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 5a04ce4750..504acbf949 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -388,13 +388,23 @@ function populate_options( array $options = array() ) { /* * translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14) * or a valid timezone string (America/New_York). See https://www.php.net/manual/en/timezones.php - * for all timezone strings supported by PHP. + * for all timezone strings currently supported by PHP. + * + * Important: When a previous timezone string, like `Europe/Kiev`, has been superseded by an + * updated one, like `Europe/Kyiv`, as a rule of thumb, the **old** timezone name should be used + * in the "translation" to allow for the default timezone setting to be PHP cross-version compatible, + * as old timezone names will be recognized in new PHP versions, while new timezone names cannot + * be recognized in old PHP versions. + * + * To verify which timezone strings are available in the _oldest_ PHP version supported, you can + * use https://3v4l.org/6YQAt#v5.6.20 and replace the "BR" (Brazil) in the code line with the + * country code for which you want to look up the supported timezone names. */ $offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); if ( is_numeric( $offset_or_tz ) ) { $gmt_offset = $offset_or_tz; - } elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list(), true ) ) { - $timezone_string = $offset_or_tz; + } elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) { + $timezone_string = $offset_or_tz; } $defaults = array( diff --git a/wp-includes/version.php b/wp-includes/version.php index ec388a3110..e5ec50a318 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54231'; +$wp_version = '6.1-alpha-54232'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.