public
Last active

Example of using the Testimonials Widget plugin for WordPress `testimonials_widget_testimonial_html` filter.

  • Download Gist
filter.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
<?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;
}
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.