Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
User timezone Auto-suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
qasedak committed Dec 30, 2020
1 parent 031d9e3 commit 2931058
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1589,8 +1589,10 @@ function pinc_enqueue_scripts()
$user_info = get_userdata($user_ID);
if(!empty($user_info->pinc_user_timezone)){
$timeZoneSet = $user_info->pinc_user_timezone;
}else{
}else if (!empty(get_option('timezone_string'))){
$timeZoneSet = get_option('timezone_string');
}else {
$timeZoneSet = "Etc/Greenwich";
}
$getUserDate = new DateTime(null, new DateTimeZone($timeZoneSet));
$currentTime = $getUserDate->format('H:i:s');
Expand Down
7 changes: 6 additions & 1 deletion page_cp_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,13 @@ function pinc_edit_user( $user_id = 0 ) {

<div class="form-group">
<label class="form-label" for="pinc_user_timezone"><?php _e('your time zone', 'pinc'); ?></label>
<?php
$apiTZ ="http://ip-api.com/json/{$_SERVER['REMOTE_ADDR']}?fields=timezone";
$userTZstr = json_decode(file_get_contents($apiTZ),1)["timezone"];
$userCurrentTZ = esc_attr($user_info->pinc_user_timezone);
?>
<select class="form-control" type="text" name="pinc_user_timezone" id="pinc_user_timezone" value="<?php echo esc_attr($user_info->pinc_user_timezone); ?>">
<option value="<?php echo esc_attr($user_info->pinc_user_timezone); ?>" selected="selected"><?php echo esc_attr($user_info->pinc_user_timezone); ?></option>
<option value="<?php if (!isset($userCurrentTZ)){ echo $userTZstr; } else { echo esc_attr($user_info->pinc_user_timezone); } ?>" selected="selected"><?php if (!isset($userCurrentTZ)){ echo $userTZstr; } else { echo esc_attr($user_info->pinc_user_timezone); } ?></option>
<option value="Pacific/Midway">(UTC-11:00) Midway Island</option>
<option value="Pacific/Samoa">(UTC-11:00) Samoa</option>
<option value="Pacific/Honolulu">(UTC-10:00) Hawaii</option>
Expand Down

0 comments on commit 2931058

Please sign in to comment.