Skip to content

Instantly share code, notes, and snippets.

@i2000s
Last active January 15, 2022 03:29
Show Gist options
  • Save i2000s/736159ea5dfaad6596503a0901f62846 to your computer and use it in GitHub Desktop.
Save i2000s/736159ea5dfaad6596503a0901f62846 to your computer and use it in GitHub Desktop.
Add an Export-to-Outlook button for The Events Calendar

This code snipet is based on the events-calendar-outlook-import-fix code. It is aiming at adding a button on the Wordpress Event page to let users export event to various calendars.

Code is licensed under the GPL 2.0 or greater license.

remove_action('tribe_events_single_event_after_the_content', array('Tribe__Events__iCal', 'single_event_links'));
add_action('tribe_events_single_event_after_the_content', 'customized_tribe_single_event_links');
function customized_tribe_single_event_links() {
if (is_single() && post_password_required()) {
return;
}
echo '<div class="tribe-events-cal-links">';
echo '<a class="tribe-events-gcal tribe-events-button" href="' . tribe_get_gcal_link() . '" title="' . __( 'Add to Google Calendar', 'tribe-events-calendar-pro' ) . '">+ Google Calendar </a>';
echo '<a class="tribe-events-gcal tribe-events-button" href="' . cquic_get_ical_outlook_link() . '">+ iCal to MS Outlook </a>';
echo '<a class="tribe-events-ical tribe-events-button" href="' . tribe_get_single_ical_link() . '">+ iCal to Mac/Apple </a>';
echo '</div><!-- .tribe-events-cal-links -->';
}
function cquic_get_ical_outlook_link() {
class CQuIC__Events__iCal extends Tribe__Events__iCal{
function cquic_ical_outlook_modify( $content ) {
$properties = explode( PHP_EOL, $content );
$searchValue = "X-WR-CALNAME";
$fl_array = preg_grep( '/^' . "$searchValue" . '.*/', $properties );
$keynum = key( $fl_array );
unset( $properties[ $keynum ] );
$content = implode( "\n", $properties );
return $content;
}
}
add_filter( 'tribe_ical_properties', 'cquic_ical_outlook_modify', 10, 2 );
$output = CQuIC__Events__iCal::get_ical_link();
return apply_filters( 'cquic_get_ical_outlook_link', $output );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment