Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created April 13, 2021 21:02
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 andrasguseo/daf37393d6664980eac41cdc8477f435 to your computer and use it in GitHub Desktop.
Save andrasguseo/daf37393d6664980eac41cdc8477f435 to your computer and use it in GitHub Desktop.
TEC > Add event description with markup to the iCal export feed.
<?php
/*
* Description: Add event description with markup to the iCal export feed.
* Usage: Paste the below snippet into your active (child) theme's functions.php file
*
* Plugin: The Events Calendar
* Author: Andras Guseo
* Last updated: 2021-04-13
*/
add_filter( 'tribe_ical_feed_item', 'tec_add_html_description_to_ical', 10, 2 );
function tec_add_html_description_to_ical( $item, $event_post ) {
$content = $event_post->post_content;
$pattern = '/(<!--).*(-->)/i';
$content = preg_replace( $pattern, '', $content );
$item['X-ALT-DESC'] = 'X-ALT-DESC:' . tec_replace( trim( str_replace( '</p>', '</p> ', $content ) ) );
return $item;
}
function tec_replace( $text = '', $search = [], $replacement = [] ) {
$search = empty( $search ) ? [ ',', "\n", "\r" ] : $search;
$replacement = empty( $replacement ) ? [ '\,', '\n', '' ] : $replacement;
return str_replace( $search, $replacement, html_entity_decode( $text, ENT_QUOTES ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment