Ticket #18146: 18146.2.diff
File 18146.2.diff, 7.4 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/user.php
diff --git src/wp-admin/includes/user.php src/wp-admin/includes/user.php index 901f437..936ed8b 100644
function edit_user( $user_id = 0 ) { 94 94 $user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; 95 95 $user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh'; 96 96 $user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false'; 97 98 // Map UTC+- timezones to gmt_offsets and set timezone_string to empty. 99 if ( !empty($_POST['timezone_string']) && preg_match('/^UTC[+-]/', $_POST['timezone_string']) ) { 100 $_POST['gmt_offset'] = $_POST['timezone_string']; 101 $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']); 102 $_POST['timezone_string'] = ''; 103 } 104 105 $user->timezone_string = isset( $_POST['timezone_string'] ) ? sanitize_text_field( $_POST['timezone_string'] ) : ''; 106 $user->gmt_offset = isset( $_POST['gmt_offset'] ) ? sanitize_text_field( $_POST['gmt_offset'] ) : ''; 97 107 } 98 108 99 109 $user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : ''; -
src/wp-admin/user-edit.php
diff --git src/wp-admin/user-edit.php src/wp-admin/user-edit.php index 6ac4a28..43ef41f 100644
elseif ( ! $user_id && ! IS_PROFILE_PAGE ) 23 23 elseif ( ! get_userdata( $user_id ) ) 24 24 wp_die( __('Invalid user ID.') ); 25 25 26 // Timezones 27 add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_user_offset' ); 28 26 29 wp_enqueue_script('user-profile'); 27 30 28 31 $title = IS_PROFILE_PAGE ? __('Profile') : __('Edit User'); … … if ( !( IS_PROFILE_PAGE && !$user_can_edit ) ) : ?> 274 277 </fieldset> 275 278 </td> 276 279 </tr> 280 <tr class="user-timezone"> 281 <?php 282 $current_offset = $profileuser->gmt_offset; 283 $tzstring = $profileuser->timezone_string; 284 285 $check_zone_info = true; 286 287 if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists 288 $check_zone_info = false; 289 if ( 0 == $current_offset ) { 290 $tzstring = 'UTC+0'; 291 } elseif ( $current_offset < 0 ) { 292 $tzstring = 'UTC' . $current_offset; 293 } else { 294 $tzstring = 'UTC+' . $current_offset; 295 } 296 } 297 ?> 298 <th scope="row"><label for="timezone"><?php _e( 'Timezone' ) ?></label 299 </th> 300 <td> 301 <select id="timezone_string" name="timezone_string"> 302 <?php echo wp_timezone_choice( $tzstring ); ?> 303 </select> 304 <span id="utc-time"><?php printf( __( '<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>' ), date_i18n( _x( 'Y-m-d G:i:s', 'timezone date format' ), false, 'gmt' ) ); ?></span> 305 <?php if ( $profileuser->timezone_string || ! empty( $current_offset ) ) : ?> 306 <span id="local-time"><?php printf( __( 'Local time is <code>%1$s</code>' ), date_i18n( _x( 'Y-m-d G:i:s', 'timezone date format' ) ) ); ?></span> 307 <?php endif; ?> 308 <p class="description"><?php _e( 'Choose a city in the same timezone as you.' ); ?></p> 309 <?php if ( $check_zone_info && $tzstring ) : ?> 310 <br /> 311 <span> 312 <?php 313 // Set TZ so localtime works. 314 date_default_timezone_set( $tzstring ); 315 $now = localtime( time(), true ); 316 if ( $now['tm_isdst'] ) 317 _e('This timezone is currently in daylight saving time.'); 318 else 319 _e('This timezone is currently in standard time.'); 320 ?> 321 <br /> 322 <?php 323 $allowed_zones = timezone_identifiers_list(); 324 325 if ( in_array( $tzstring, $allowed_zones ) ) { 326 $found = false; 327 $date_time_zone_selected = new DateTimeZone($tzstring); 328 $tz_offset = timezone_offset_get( $date_time_zone_selected, date_create() ); 329 $right_now = time(); 330 foreach ( timezone_transitions_get( $date_time_zone_selected ) as $tr ) { 331 if ( $tr['ts'] > $right_now ) { 332 $found = true; 333 break; 334 } 335 } 336 337 if ( $found ) { 338 echo ' '; 339 $message = $tr['isdst'] ? 340 __('Daylight saving time begins on: <code>%s</code>.') : 341 __('Standard time begins on: <code>%s</code>.'); 342 // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). 343 printf( $message, date_i18n( get_option('date_format') . ' ' . get_option( 'time_format' ), $tr['ts'] + ($tz_offset - $tr['offset']) ) ); 344 } else { 345 _e( 'This timezone does not observe daylight saving time.' ); 346 } 347 } 348 // Set back to UTC. 349 date_default_timezone_set( 'UTC' ); 350 ?> 351 </span> 352 <?php endif; ?> 353 </td> 354 </tr> 277 355 <?php 278 356 /** 279 357 * Fires at the end of the 'Personal Options' settings table on the user editing screen. -
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index 7bf0388..8c20c0a 100644
add_action( 'init', '_show_post_preview' ); 292 292 293 293 // Timezone 294 294 add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' ); 295 if ( is_admin() ) { 296 add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_user_offset' ); 297 } 295 298 296 299 // Admin Color Schemes 297 300 add_action( 'admin_init', 'register_admin_color_schemes', 1); -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index b09ed84..bcb8690 100644
function wp_timezone_override_offset() { 3965 3965 } 3966 3966 3967 3967 /** 3968 * Overrides the gmt_offset with the current user's offset, if available. 3969 * 3970 * @since 4.3.0 3971 * 3972 * @return float|false Timezone GMT offset, false otherwise. 3973 */ 3974 function wp_timezone_override_user_offset() { 3975 global $user_id; 3976 3977 if ( ! $user_id ) { 3978 $user_id = get_current_user_id(); 3979 } 3980 3981 $timezone_string = get_user_meta( $user_id, 'timezone_string', true ); 3982 3983 if ( $timezone_string ) { 3984 $timezone_object = timezone_open( $timezone_string ); 3985 $datetime_object = date_create(); 3986 if ( false !== $timezone_object || false !== $datetime_object ) { 3987 $offset = round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 ); 3988 } 3989 } else { 3990 $offset = get_user_meta( $user_id, 'gmt_offset', true ); 3991 } 3992 3993 return $offset ? $offset : false; 3994 } 3995 3996 /** 3968 3997 * Sort-helper for timezones. 3969 3998 * 3970 3999 * @since 2.9.0 -
src/wp-includes/user.php
diff --git src/wp-includes/user.php src/wp-includes/user.php index cb9695c..107421c 100644
function wp_insert_user( $userdata ) { 2025 2025 2026 2026 $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; 2027 2027 2028 $meta['gmt_offset'] = empty( $userdata['gmt_offset'] ) ? '' : $userdata['gmt_offset']; 2029 $meta['timezone_string'] = empty( $userdata['timezone_string'] ) ? '' : $userdata['timezone_string']; 2030 2028 2031 $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login)); 2029 2032 2030 2033 if ( $user_nicename_check ) { … … function wp_create_user($username, $password, $email = '') { 2205 2208 * @return array 2206 2209 */ 2207 2210 function _get_additional_user_keys( $user ) { 2208 $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' );2211 $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'gmt_offset', 'timezone_string' ); 2209 2212 return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); 2210 2213 } 2211 2214