Created
June 21, 2013 19:31
-
-
Save michael-cannon/5833700 to your computer and use it in GitHub Desktop.
Filter testimonials_widget_content example
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
add_filter( 'testimonials_widget_content', array( &$this, 'truncate_content' ), 10, 4 ); | |
public function truncate_content( $content, $widget_number, $source, $atts ) { | |
$char_limit = $atts['char_limit']; | |
$excerpt_read_more = $atts['excerpt_read_more']; | |
$force_read_more = $atts['force_read_more']; | |
$hide_read_more = $atts['hide_read_more']; | |
$nofollow_read_more = $atts['nofollow_read_more']; | |
$content_bare = strip_tags( $content ); | |
if ( ! $force_read_more ) { | |
if ( $hide_read_more ) { | |
return $content; | |
} elseif ( ! $excerpt_read_more ) { | |
if ( empty( $char_limit ) || strlen( $content_bare ) <= $char_limit ) | |
return $content; | |
} | |
} | |
if ( empty( $source['post_id'] ) ) | |
return $content; | |
// regenerate content | |
$content = $source['testimonial_content']; | |
$content = Testimonials_Widget::format_content( $content, $widget_number, $atts ); | |
if ( empty ( $source['testimonial_read_more_link'] ) ) { | |
$post_id = $source['post_id']; | |
$post_permalink = post_permalink( $post_id ); | |
} else { | |
$post_permalink = $source['testimonial_read_more_link']; | |
} | |
$post_title = $source['testimonial_source']; | |
$close_quote = Testimonials_Widget::$tag_close_quote; | |
$content = preg_replace( '#' . $close_quote . '.*$#', '', $content ); | |
$more_text = ''; | |
if ( ! empty( $char_limit ) && strlen( $content_bare ) > $char_limit ) | |
$more_text .= apply_filters( 'testimonials_widget_premium_more_ellipsis', __( '…', 'testimonials-widget-premium' ) ); | |
$more_text .= $close_quote; | |
$more_text .= ' '; | |
$more_text .= '<a href="'; | |
$more_text .= $post_permalink; | |
$more_text .= '"'; | |
if ( $nofollow_read_more ) | |
$more_text .= ' rel="nofollow"'; | |
$more_text .= ' title="'; | |
$more_text .= apply_filters( 'testimonials_widget_premium_link_title_text', __( 'Complete testimonial by ', 'testimonials-widget-premium' ) ); | |
$more_text .= $post_title; | |
$more_text .= '" class="more-link">'; | |
$more_text .= apply_filters( 'testimonials_widget_premium_more_text', __( 'Read more', 'testimonials-widget-premium' ) ); | |
$more_text .= '</a>'; | |
$content = Testimonials_Widget::testimonials_truncate( $content, $char_limit, $more_text, true ); | |
$content = force_balance_tags( $content ); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment