Team Time Zones Widget
Adds a dashboard widget showing the current local time for each office or teammate you list, next to the site's own time, so scheduling across time zones is easier.
Opens WPIDE on
Code
// Label => PHP time zone name.
$wpide_team_zones = array(
'London' => 'Europe/London',
'New York' => 'America/New_York',
'Sydney' => 'Australia/Sydney',
);
add_action( 'wp_dashboard_setup', function () use ( $wpide_team_zones ) {
wp_add_dashboard_widget( 'wpide_team_zones', 'Team time zones', function () use ( $wpide_team_zones ) {
$format = get_option( 'time_format' );
$zones = array( 'Site time' => wp_timezone() );
foreach ( $wpide_team_zones as $label => $zone ) {
try {
$zones[ $label ] = new DateTimeZone( $zone );
} catch ( Exception $e ) {
continue;
}
}
echo '<table class="widefat striped"><tbody>';
foreach ( $zones as $label => $zone ) {
$now = new DateTime( 'now', $zone );
printf(
'<tr><td>%s</td><td style="text-align:right"><strong>%s</strong> <small style="color:#646970">%s</small></td></tr>',
esc_html( $label ),
esc_html( wp_date( $format, $now->getTimestamp(), $zone ) ),
esc_html( wp_date( 'D', $now->getTimestamp(), $zone ) )
);
}
echo '</tbody></table>';
} );
} );
Notes
Use PHP time zone names such as Europe/London or America/New_York in $wpide_team_zones.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.