Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Created September 30, 2014 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesseeproductions/8776fc45363f674d6ae6 to your computer and use it in GitHub Desktop.
Save jesseeproductions/8776fc45363f674d6ae6 to your computer and use it in GitHub Desktop.
The Events Calendar Filter for RSS Feed to Correct Pubdate
/*
* The Events Calendar Filter for RSS Feed to Correct Pubdate
* Modifys the first $zone check as UTC time 0 was registering as === false
*/
add_filter( 'get_post_time', 'events_rss2_gmt_pubdate_correction', 20 , 3 );
function events_rss2_gmt_pubdate_correction($time, $d, $gmt) {
global $post;
// Don't interfere if this is not the events feed
if ( $post->post_type != TribeEvents::POSTTYPE || ! is_feed() || ! $gmt ) return $time;
// Don't interfere if the timezone hasn't been set
$zone = get_option( 'timezone_string', false );
if ( !$zone ) {
return $time;
}
// Get time and timezone
$time = new DateTime( tribe_get_start_date( $post->ID, false, $d ) );
$zone = new DateTimeZone($zone);
// Apply timezone and calculate offset
$time->setTimezone( $zone );
$offset = $zone->getOffset( $time );
$offset *= -2;
// Apply correction
$time->modify( "$offset seconds" );
$time = $time->format( TribeDateUtils::DBDATETIMEFORMAT );
$time = mysql2date( $d, $time );
return $time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment