Ticket #18146: 18146.3.diff
File 18146.3.diff, 7.4 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/user.php
diff --git src/wp-admin/includes/user.php src/wp-admin/includes/user.php index fc46dd3..149ba88 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 bb3c62e..0aeed39 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 ) ) : ?> 269 272 </fieldset> 270 273 </td> 271 274 </tr> 275 <tr class="user-timezone"> 276 <?php 277 $current_offset = $profileuser->gmt_offset; 278 $tzstring = $profileuser->timezone_string; 279 280 $check_zone_info = true; 281 282 if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists 283 $check_zone_info = false; 284 if ( 0 == $current_offset ) { 285 $tzstring = 'UTC+0'; 286 } elseif ( $current_offset < 0 ) { 287 $tzstring = 'UTC' . $current_offset; 288 } else { 289 $tzstring = 'UTC+' . $current_offset; 290 } 291 } 292 ?> 293 <th scope="row"><label for="timezone"><?php _e( 'Timezone' ) ?></label 294 </th> 295 <td> 296 <select id="timezone_string" name="timezone_string"> 297 <?php echo wp_timezone_choice( $tzstring ); ?> 298 </select> 299 <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> 300 <?php if ( $profileuser->timezone_string || ! empty( $current_offset ) ) : ?> 301 <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> 302 <?php endif; ?> 303 <p class="description"><?php _e( 'Choose a city in the same timezone as you.' ); ?></p> 304 <?php if ( $check_zone_info && $tzstring ) : ?> 305 <br /> 306 <span> 307 <?php 308 // Set TZ so localtime works. 309 date_default_timezone_set( $tzstring ); 310 $now = localtime( time(), true ); 311 if ( $now['tm_isdst'] ) 312 _e('This timezone is currently in daylight saving time.'); 313 else 314 _e('This timezone is currently in standard time.'); 315 ?> 316 <br /> 317 <?php 318 $allowed_zones = timezone_identifiers_list(); 319 320 if ( in_array( $tzstring, $allowed_zones ) ) { 321 $found = false; 322 $date_time_zone_selected = new DateTimeZone($tzstring); 323 $tz_offset = timezone_offset_get( $date_time_zone_selected, date_create() ); 324 $right_now = time(); 325 foreach ( timezone_transitions_get( $date_time_zone_selected ) as $tr ) { 326 if ( $tr['ts'] > $right_now ) { 327 $found = true; 328 break; 329 } 330 } 331 332 if ( $found ) { 333 echo ' '; 334 $message = $tr['isdst'] ? 335 __('Daylight saving time begins on: <code>%s</code>.') : 336 __('Standard time begins on: <code>%s</code>.'); 337 // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). 338 printf( $message, date_i18n( get_option('date_format') . ' ' . get_option( 'time_format' ), $tr['ts'] + ($tz_offset - $tr['offset']) ) ); 339 } else { 340 _e( 'This timezone does not observe daylight saving time.' ); 341 } 342 } 343 // Set back to UTC. 344 date_default_timezone_set( 'UTC' ); 345 ?> 346 </span> 347 <?php endif; ?> 348 </td> 349 </tr> 272 350 <?php 273 351 /** 274 352 * 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 3402e48..142da78 100644
add_action( 'wp_head', 'wp_post_preview_js', 1 ); 330 330 331 331 // Timezone 332 332 add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' ); 333 if ( is_admin() ) { 334 add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_user_offset' ); 335 } 333 336 334 337 // Admin Color Schemes 335 338 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 e3f2560..0a71b91 100644
function wp_timezone_override_offset() { 4445 4445 } 4446 4446 4447 4447 /** 4448 * Overrides the gmt_offset with the current user's offset, if available. 4449 * 4450 * @since 4.7.0 4451 * 4452 * @return float|false Timezone GMT offset if available, false otherwise. 4453 */ 4454 function wp_timezone_override_user_offset( $offset ) { 4455 global $user_id; 4456 4457 if ( ! $user_id ) { 4458 $user_id = get_current_user_id(); 4459 } 4460 4461 $timezone_string = get_user_meta( $user_id, 'timezone_string', true ); 4462 4463 if ( $timezone_string ) { 4464 $timezone_object = timezone_open( $timezone_string ); 4465 $datetime_object = date_create(); 4466 if ( false !== $timezone_object || false !== $datetime_object ) { 4467 $offset = round( timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS, 2 ); 4468 } 4469 } else { 4470 $offset = get_user_meta( $user_id, 'gmt_offset', true ); 4471 } 4472 4473 return $offset; 4474 } 4475 4476 /** 4448 4477 * Sort-helper for timezones. 4449 4478 * 4450 4479 * @since 2.9.0 -
src/wp-includes/user.php
diff --git src/wp-includes/user.php src/wp-includes/user.php index 9ff6455..0f17002 100644
function wp_insert_user( $userdata ) { 1592 1592 1593 1593 $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front']; 1594 1594 1595 $meta['gmt_offset'] = empty( $userdata['gmt_offset'] ) ? '' : $userdata['gmt_offset']; 1596 $meta['timezone_string'] = empty( $userdata['timezone_string'] ) ? '' : $userdata['timezone_string']; 1597 1595 1598 $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)); 1596 1599 1597 1600 if ( $user_nicename_check ) { … … function wp_create_user($username, $password, $email = '') { 1951 1954 * @return array List of user keys to be populated in wp_update_user(). 1952 1955 */ 1953 1956 function _get_additional_user_keys( $user ) { 1954 $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' );1957 $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'gmt_offset', 'timezone_string' ); 1955 1958 return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); 1956 1959 } 1957 1960