Date/Time: Correct timezone dropdown list creation in `wp_timezone_choice()`.
This fixes a bug where if the `timezone_string` is set to a timezone name which has since been deprecated, no option would be (pre-)selected in the generated dropdown list and when the form using the dropdown list is submitted, the “old”, originally saved value would be lost as the form would submit without a value being selected for the `timezone_string` field. The fix is a little hacky: it basically checks ahead of generating the actual dropdown list whether the `$selected_zone` value would be recognized and set to “selected” and if not, verifies that the value ''is'' a valid but outdated timezone name and if so, adds an extra dropdown entry to the top of the list with the original value and sets this value to “selected”. 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()]. Note: There are no pre-existing tests at all for this method and adding a complete set of tests for this method is outside the scope of this ticket, so this fix does not contain any tests. Follow-up to [54207], [54217], [54227], [54229], [54230], [54232]. Props jrf, costdev, marcyoast. See #56468. Built from https://develop.svn.wordpress.org/trunk@54233 git-svn-id: http://core.svn.wordpress.org/trunk@53792 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3d18a0c264
commit
526dba25c2
|
@ -6381,8 +6381,10 @@ function wp_timezone_choice( $selected_zone, $locale = null ) {
|
||||||
$mo_loaded = true;
|
$mo_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tz_identifiers = timezone_identifiers_list();
|
||||||
$zonen = array();
|
$zonen = array();
|
||||||
foreach ( timezone_identifiers_list() as $zone ) {
|
|
||||||
|
foreach ( $tz_identifiers as $zone ) {
|
||||||
$zone = explode( '/', $zone );
|
$zone = explode( '/', $zone );
|
||||||
if ( ! in_array( $zone[0], $continents, true ) ) {
|
if ( ! in_array( $zone[0], $continents, true ) ) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -6417,6 +6419,13 @@ function wp_timezone_choice( $selected_zone, $locale = null ) {
|
||||||
$structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>';
|
$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 ) {
|
foreach ( $zonen as $key => $zone ) {
|
||||||
// Build value in an array to join later.
|
// Build value in an array to join later.
|
||||||
$value = array( $zone['continent'] );
|
$value = array( $zone['continent'] );
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.1-alpha-54232';
|
$wp_version = '6.1-alpha-54233';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue