Skip to content

Instantly share code, notes, and snippets.

@michael-cannon
Last active December 9, 2015 21:58
Show Gist options
  • Save michael-cannon/4333863 to your computer and use it in GitHub Desktop.
Save michael-cannon/4333863 to your computer and use it in GitHub Desktop.
Example of using the Testimonials Widget plugin for WordPress `testimonials_widget_testimonial_html` filter.
<?php
add_filter( 'testimonials_widget_testimonial_html', 'my_testimonials_widget_testimonial_html', 10, 6 );
// this function is a copy of Testimonials_Widget::get_testimonial_html and completely ignores what's in $content
function my_testimonials_widget_testimonial_html( $content, $testimonial, $atts, $is_list = true, $is_first = false, $widget_number = null ) {
$atts = wp_parse_args( $atts, Testimonials_Widget::get_defaults( true ) );
$atts = Testimonials_Widget_Settings::validate_settings( $atts );
// display attributes
$disable_quotes = $atts['disable_quotes'];
$do_image = ! $atts['hide_image'] && ! empty( $testimonial['testimonial_image'] );
$do_image_single = ! $atts['hide_image_single'];
$keep_whitespace = $atts['keep_whitespace'];
$remove_hentry = $atts['remove_hentry'];
$class = 'testimonials-widget-testimonial';
if ( is_single() && empty( $widget_number ) ) {
$class .= ' single';
} elseif ( $is_list ) {
$class .= ' list';
} elseif ( $is_first ) {
$class .= ' active';
} elseif ( ! $is_first ) {
$class .= ' display-none';
}
if ( $keep_whitespace )
$class .= ' whitespace';
if ( ! empty( $testimonial['post_id'] ) )
$class = join( ' ', get_post_class( $class, $testimonial['post_id'] ) );
else
$class = 'testimonials-widget type-testimonials-widget status-publish hentry ' . $class;
$class = apply_filters( 'testimonials_widget_get_testimonial_html_class', $class, $testimonial, $atts, $is_list, $is_first, $widget_number );
$div_open = '<div class="' . $class . '">';
if ( $remove_hentry )
$div_open = str_replace( ' hentry', '', $div_open );
$image = '';
if ( $do_image ) {
$image .= '<span class="image">';
$image .= $testimonial['testimonial_image'];
$image .= '</span>';
}
if ( ! $do_image_single && 'get_single' == $atts['type'] )
$image = '';
$quote = Testimonials_Widget::get_quote( $testimonial, $atts, $widget_number );
$cite = Testimonials_Widget::get_cite( $testimonial, $atts );
$extra = '';
if ( ! empty( $testimonial['testimonial_extra'] ) ) {
$extra .= '<div class="extra">';
$extra .= $testimonial['testimonial_extra'];
$extra .= '</div>';
}
$bottom_text = '';
if ( ! empty( $atts['bottom_text'] ) ) {
$bottom_text = '<div class="bottom_text">';
$bottom_text .= $atts['bottom_text'];
$bottom_text .= '</div>';
}
$div_close = '</div>';
$html = $div_open
. $image
. $quote
. $cite
. $extra
. $bottom_text
. $div_close;
// not done sooner as tag_close_quote is used for Premium
if ( $disable_quotes ) {
$html = str_replace( Testimonials_Widget::$tag_open_quote, '', $html );
$html = str_replace( Testimonials_Widget::$tag_close_quote, '', $html );
}
return $html;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment