[wp-trac] [WordPress Trac] #63483: Compatibility float and whitelist timezone string

WordPress Trac noreply at wordpress.org
Tue Jun 3 16:57:51 UTC 2025


#63483: Compatibility float and whitelist timezone string
--------------------------------+--------------------------------
 Reporter:  autotutorial        |       Owner:  (none)
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  php-compatibility
--------------------------------+--------------------------------
Changes (by autotutorial):

 * focuses:   => php-compatibility
 * severity:  trivial => normal


Comment:

 Hi everyone, please set $_POST['timezone string'] as required. In my
 pseudo php code, if $_POST['timezone_string'] is absent or invalid, set
 the error and then recover by setting $_POST['timezone_string'] and
 $_POST['gmt_offset'] from the respective functions
 get_option('timezone_string') for the timezone ID and
 get_option('gmt_offset') for the manual offset.

 In the option.php file $value is null if it doesn't exist, I don't think
 you want to set timezone_string and gmt_offset to anything other than
 explicit choice.

 {{{#!php
 <?php
         unset( $_POST['gmt_offset'] );
     $first = 'UTC';
         $second = 'UTC+';
         $offset_range = array(
                 '',
                 $first . '-12',
                 $first . '-11.5',
                 $first . '-11',
                 $first . '-10.5',
                 $first . '-10',
                 $first . '-9.5',
                 $first . '-9',
                 $first . '-8.5',
                 $first . '-8',
                 $first . '-7.5',
                 $first . '-7',
                 $first . '-6.5',
                 $first . '-6',
                 $first . '-5.5',
                 $first . '-5',
                 $first . '-4.5',
                 $first . '-4',
                 $first . '-3.5',
                 $first . '-3',
                 $first . '-2.5',
                 $first . '-2',
                 $first . '-1.5',
                 $first . '-1',
                 $first . '-0.5',
                 $second . '0',
                 $second . '0.5',
                 $second . '1',
                 $second . '1.5',
                 $second . '2',
                 $second . '2.5',
                 $second . '3',
                 $second . '3.5',
                 $second . '4',
                 $second . '4.5',
                 $second . '5',
                 $second . '5.5',
                 $second . '5.75',
                 $second . '6',
                 $second . '6.5',
                 $second . '7',
                 $second . '7.5',
                 $second . '8',
                 $second . '8.5',
                 $second . '8.75',
                 $second . '9',
                 $second . '9.5',
                 $second . '10',
                 $second . '10.5',
                 $second . '11',
                 $second . '11.5',
                 $second . '12',
                 $second . '12.75',
                 $second . '13',
                 $second . '13.75',
                 $second . '14',
         );
         if ( empty($_POST['timezone_string'] ) ) {
                 $_POST['timezone_string'] = '';
         }

         $key_valid1 = array_search( $_POST['timezone_string'],
 $offset_range );
          if ( $key_valid ) {
                 $_POST['gmt_offset'] = strtr( $offset_range[$key_valid1],
 array( 'UTC+' => '', 'UTC' => '' ) );
                 $_POST['timezone_string'] = '';
         } else {
                 $tz_identifiers = timezone_identifiers_list(
 DateTimeZone::ALL_WITH_BC );
                 $key_valid2 = array_search( $_POST['timezone_string'],
 $tz_identifiers );
                 if ( false === $key_valid2 ) {
                         //Reset to the current value
                         $key_valid2 = array_search(
 get_option('timezone_string' ), $tz_identifiers );
                         add_settings_error(
                         'general',
                         'settings_updated',
                         __( 'The timezone you have entered is not valid.
 Please select a valid timezone.' ),
                         'error'
                         );
                 }

                 if ( is_int( $key_valid2 ) ) {
                         $_POST['gmt_offset'] = '';
                         $_POST['timezone_string'] =
 $tz_identifiers[$key_valid2];
                 } else {
                         $key_valid1 = (int) array_search( strtr( 'UTC+' .
 get_option( 'gmt_offset' ), array('+-' => '-', ',' => '.' ) ),
 $offset_range );
                         $_POST['gmt_offset'] = strtr(
 $offset_range[$key_valid1], array( 'UTC+' => '', 'UTC' => '' ) );
                         $_POST['timezone_string'] = '';
                 }
         }
         unset( $offset_range, $tz_identifiers );
 ?>
 }}}

 Thank for reading.
 The gmt_offset when it comes to sanitize_option use preg_replace if
 instead of null you can edit and remove is_numeric added for php 8
 compatibility.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63483#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list