Skip to content

Instantly share code, notes, and snippets.

@afragen
Last active June 8, 2022 21:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afragen/2831526 to your computer and use it in GitHub Desktop.
Save afragen/2831526 to your computer and use it in GitHub Desktop.
Modify Event Calendar iCal feed properties for Outlook
<?php
//Add the following to your theme's functions.php
add_filter( 'tribe_ical_properties', 'tribe_ical_outlook_modify', 10, 2 );
function tribe_ical_outlook_modify( $content ) {
$properties = preg_split ( '/$\R?^/m', $content );
$searchValue = "X-WR-CALNAME";
$fl_array = preg_grep('/^' . "$searchValue" . '.*/', $properties);
$key = array_values($fl_array);
$keynum = key($fl_array);
unset($properties[$keynum]);
$content = implode( "\n", $properties );
return $content;
}
?>
@afragen
Copy link
Author

afragen commented Jun 1, 2012

This will remove the line in the ics file that begins X-WR-CALNAME

@afragen
Copy link
Author

afragen commented Jun 9, 2012

Changes $headers to $properties to more accurately reflect the actual iCalendar naming.

@mamamaia
Copy link

HI

Does this work with free https://wordpress.org/plugins/the-events-calendar/ plugin?
I am getting same problem, need to fix this :)

Thanks

@afragen
Copy link
Author

afragen commented Jul 2, 2014

@mamamaia, it should. I think Modern Tribe moved the iCal event export code from he PRO plugin to the core plugin. If this happened then this solution should work fine, otherwise nothing will happen.

@afragen
Copy link
Author

afragen commented Jul 26, 2014

Consider explode instead of preg_split

@mrwweb
Copy link

mrwweb commented Jun 8, 2022

With inspiration from this gist and wanting to remove a few other values, I landed on this. Seems to be working well and will hopefully have it in production soon.

add_filter( 'tribe_ical_properties', 'tribe_ical_outlook_modify', 999 );
function tribe_ical_outlook_modify( $content ) {
	$headers = explode( PHP_EOL, $content );
	$headers = array_filter( $content , function($val) {
		return ! preg_match('/X-WR-CALNAME|X-WR-CALDESC|REFRESH-INTERVAL/i', $val);
	});
	return implode( PHP_EOL, $content );
}

A couple notes:

  • I was running this in an mu-plugin and needed a high priority to run last
  • I think there's a bug in the above gist as the add_filter() calls for two parameter, but I only one is provided by the filter and accepted by the callback function.

@afragen
Copy link
Author

afragen commented Jun 8, 2022

This is actually a plugin on dot org and has been incorporated into the latest version of The Events Calendar.

@mrwweb
Copy link

mrwweb commented Jun 8, 2022

@afragen Really? Interesting. Do you have a link or more info? I didn't come across it when researching this need. I've got things working now with my code, but definitely want to know what other options are out there.

@mrwweb
Copy link

mrwweb commented Jun 8, 2022

@afragen Thanks for sharing. I totally missed that, as we weren't thinking about Outlook but instead wanting to avoid that for Apple devices. I did see the additions to TEC, but we're hoping to make the change globally, so the custom code was (I think) still required for us. Appreciate the pointers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment