I have been googling for this and (again) I had to come up with my own solution.
function my_set_gmt_offset($offset) {
global $wpdb;
/* WordPress default sets to UTC timezone
in wp-settings.php.
you can change this line to whatever your timezone is.
I set it to my timezone (NY)
More: http://www.php.net/manual/en/timezones.php
*/
if(function_exists('date_default_timezone_set'))
date_default_timezone_set('America/New_York');
$timezone = date("T");
/* Now we have your local timezone stored in $timezone
so lets restore wordpress setting as in wp-settings.php */
if ( function_exists('date_default_timezone_set') )
date_default_timezone_set('UTC');
$current_offset = $offset;
if($timezone == 'EDT') {
$offset = '-4';
}
else if($timezone == 'EST') {
$offset = '-5';
}
if($offset != $current_offset) {
/* update offset in database if new offset is different.
Do not use update_option since it will call
this filter again and cause infinite loop.
*/
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options
SET option_value = %s WHERE
option_name = %s", $offset, 'gmt_offset' ) );
/* let wordpress regenerate cache from database */
wp_cache_set('gmt_offset', 'checkthedatabaseplease', 'options');
}
return $offset;
}
add_filter('option_gmt_offset', 'my_set_gmt_offset');
Share your feedback via comments.
This would be a good idea. Quite useful too.