Created
April 13, 2021 21:02
-
-
Save andrasguseo/daf37393d6664980eac41cdc8477f435 to your computer and use it in GitHub Desktop.
TEC > Add event description with markup to the iCal export feed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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