Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Forked from joshfeck/ical_offset_example.php
Last active July 26, 2022 15:56
Show Gist options
  • Save Pebblo/e031f4768cf863368a0099bc097fd04b to your computer and use it in GitHub Desktop.
Save Pebblo/e031f4768cf863368a0099bc097fd04b to your computer and use it in GitHub Desktop.
This allows you to change the timezone used for the iCal data, if a custom field value is present it will be used to set the timezone on the datetime. Useful for sites that have events in different timezones
<?php //* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'FHEE__EED_Ical__download_ics_file_ics_data',
'my_custom_ical_timezone_output_filter',
10,
2
);
function my_custom_ical_timezone_output_filter(
$ics_data,
$datetime
) {
$event = $datetime->event();
if($event instanceof EE_Event) {
$timezone = $event->get_post_meta('event_timezone', true);
if(! empty($timezone)) {
$datetime->set_timezone($timezone);
$ics_data['DTSTART'] = date(
EED_Ical::iCal_datetime_format,
EEH_DTT_Helper::get_timestamp_with_offset(
$datetime->start(),
$timezone
)
);
$ics_data['DTEND'] = date(
EED_Ical::iCal_datetime_format,
EEH_DTT_Helper::get_timestamp_with_offset(
$datetime->end(),
$timezone
)
);
}
}
return $ics_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment