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.
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.
/** | |
* Add Outlook calendar export links | |
* irkanu: https://gist.github.com/irkanu/01b30869f5af1fa405d1 | |
* GeoffEW: https://gist.github.com/GeoffEW/b8f0bb5fc2b8510c6ad4f0b60fcf3fb9 | |
*/ | |
class Tribe__Events__Remove__Export__Links { | |
public function __construct() { | |
add_action( 'init', array( $this, 'single_event_links' ) ); | |
} | |
public function single_event_links() { | |
remove_action( | |
'tribe_events_single_event_after_the_content', | |
array( $this->ical_provider(), 'single_event_links' ) | |
); | |
// Add "Export to Outlook" buton on single events | |
add_action('tribe_events_single_event_after_the_content', 'customized_tribe_single_event_links'); | |
} | |
protected function ical_provider() { | |
return function_exists( 'tribe' ) | |
? tribe( 'tec.iCal' ) // Current | |
: 'Tribe__Events__iCal'; // Legacy | |
} | |
} | |
new Tribe__Events__Remove__Export__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 ); | |
} |