Last active
December 21, 2015 21:50
-
-
Save geoffgraham/a1727befcced597910b8 to your computer and use it in GitHub Desktop.
The Events Calendar 4.0.2 // Add HTML to Excerpts
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 | |
/** | |
* Plugin Name: The Events Calendar: Add HTML to Excerpts | |
* Plugin URI: http://theeventscalendar.com | |
* Description: Ensure that allowed HTML is preserved in Events Calendar tooltips. | |
* Version: 0.0.1 | |
* Author: Modern Tribe | |
* | |
* @link http://theeventscalendar.com/?p=1038901 | |
*/ | |
add_filter( 'wp_trim_words', 'tribe_support_1038901', 10, 4 ); | |
function tribe_support_1038901( $text, $num_words, $more, $original_text ) { | |
if ( null === $more ) { | |
$more = '…'; | |
} | |
$text = $original_text; | |
if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { | |
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); | |
preg_match_all( '/./u', $text, $words_array ); | |
$words_array = array_slice( $words_array[0], 0, $num_words + 1 ); | |
$sep = ''; | |
} else { | |
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); | |
$sep = ' '; | |
} | |
if ( count( $words_array ) > $num_words ) { | |
array_pop( $words_array ); | |
$text = implode( $sep, $words_array ); | |
$text = $text . $more; | |
} else { | |
$text = implode( $sep, $words_array ); | |
} | |
return $text; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment