Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions classes/class-woothemes-testimonials.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Woothemes_Testimonials {
private $assets_dir;
private $assets_url;
private $token;
public $version;
public $version;
private $file;

/**
Expand Down Expand Up @@ -344,34 +344,34 @@ public function enqueue_admin_styles () {
* @since 1.0.0
* @return array
*/
public function get_custom_fields_settings () {
public function get_custom_fields_settings() {
$fields = array();

$fields['gravatar_email'] = array(
'name' => __( 'Gravatar E-mail Address', 'woothemes-testimonials' ),
'description' => sprintf( __( 'Enter in an e-mail address, to use a %sGravatar%s, instead of using the "Featured Image".', 'woothemes-testimonials' ), '<a href="' . esc_url( 'http://gravatar.com/' ) . '" target="_blank">', '</a>' ),
'type' => 'text',
'default' => '',
'section' => 'info'
'name' => __( 'Gravatar E-mail Address', 'woothemes-testimonials' ),
'description' => sprintf( __( 'Enter in an e-mail address, to use a %sGravatar%s, instead of using the "Featured Image".', 'woothemes-testimonials' ), '<a href="' . esc_url( 'http://gravatar.com/' ) . '" target="_blank">', '</a>' ),
'type' => 'text',
'default' => '',
'section' => 'info',
);

$fields['byline'] = array(
'name' => __( 'Byline', 'woothemes-testimonials' ),
'description' => __( 'Enter a byline for the customer giving this testimonial (for example: "CEO of WooThemes").', 'woothemes-testimonials' ),
'type' => 'text',
'default' => '',
'section' => 'info'
'name' => __( 'Byline', 'woothemes-testimonials' ),
'description' => __( 'Enter a byline for the customer giving this testimonial (for example: "CEO of WooThemes").', 'woothemes-testimonials' ),
'type' => 'text',
'default' => '',
'section' => 'info',
);

$fields['url'] = array(
'name' => __( 'URL', 'woothemes-testimonials' ),
'description' => __( 'Enter a URL that applies to this customer (for example: http://woothemes.com/).', 'woothemes-testimonials' ),
'type' => 'url',
'default' => '',
'section' => 'info'
'name' => __( 'URL', 'woothemes-testimonials' ),
'description' => __( 'Enter a URL that applies to this customer (for example: http://woothemes.com/).', 'woothemes-testimonials' ),
'type' => 'url',
'default' => '',
'section' => 'info',
);

return $fields;
return apply_filters( 'testimonials_get_custom_fields_settings', $fields );
} // End get_custom_fields_settings()

/**
Expand Down
6 changes: 4 additions & 2 deletions classes/class-woothemes-widget-testimonials.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,7 @@ protected function get_order_options () {
} // End Class

/* Register the widget. */
add_action( 'widgets_init', create_function( '', 'return register_widget("Woothemes_Widget_Testimonials");' ), 1 );
?>
add_action( 'widgets_init', function() {
return register_widget( 'Woothemes_Widget_Testimonials' );
}, 1 );
?>
105 changes: 89 additions & 16 deletions woothemes-testimonials-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ function woothemes_testimonials ( $args = '' ) {
// Allow child themes/plugins to filter here.
$args = apply_filters( 'woothemes_testimonials_args', $args );
$html = '';

do_action( 'woothemes_testimonials_before', $args );

// The Query.
Expand Down Expand Up @@ -85,11 +84,13 @@ function woothemes_testimonials ( $args = '' ) {
$html .= '<div class="testimonials-list">' . "\n";

// Begin templating logic.
$tpl = '<div id="quote-%%ID%%" class="%%CLASS%%" itemprop="review" itemscope itemtype="http://schema.org/Review"><blockquote class="testimonials-text" itemprop="reviewBody">%%TEXT%%</blockquote>%%AVATAR%% %%AUTHOR%%</div>';
$tpl = '<div id="quote-%%ID%%" class="%%CLASS%%"><blockquote class="testimonials-text">%%TEXT%%</blockquote>%%AVATAR%% %%AUTHOR%%</div>';
$tpl = apply_filters( 'woothemes_testimonials_item_template', $tpl, $args );

$count = 0;
foreach ( $query as $post ) { $count++;
foreach ( $query as $post ) {
$count++;

$template = $tpl;

$css_class = 'quote';
Expand All @@ -105,21 +106,23 @@ function woothemes_testimonials ( $args = '' ) {

$author = '';
$author_text = '';

// If we need to display the author, get the data.
if ( ( get_the_title( $post ) != '' ) && true == $args['display_author'] ) {
$author .= '<cite class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">';
$post_title = get_the_title( $post );
$byline = $post->byline;
$author_url = esc_url( $post->url );
if ( ( $post_title != '' ) && true == $args['display_author'] ) {
$author .= '<cite class="author">';

$author_name = '<span itemprop="name">' . get_the_title( $post ) . '</span>';
$author_name = '<span>' . $post_title . '</span>';

$author .= $author_name;

if ( isset( $post->byline ) && '' != $post->byline ) {
$author .= ' <span class="title" itemprop="jobTitle">' . $post->byline . '</span><!--/.title-->' . "\n";
if ( isset( $byline ) && '' != $byline ) {
$author .= ' <span class="title">' . $byline . '</span><!--/.title-->' . "\n";
}

if ( true == $args['display_url'] && '' != $post->url ) {
$author .= ' <span class="url"><a href="' . esc_url( $post->url ) . '" itemprop="url">' . apply_filters( 'woothemes_testimonials_author_link_text', $text = esc_url( $post->url ) ) . '</a></span><!--/.excerpt-->' . "\n";
if ( true == $args['display_url'] && '' != $author_url ) {
$author .= ' <span class="url"><a href="' . esc_url( $author_url ) . '">' . apply_filters( 'woothemes_testimonials_author_link_text', $text = esc_url( $author_url ) ) . '</a></span><!--/.excerpt-->' . "\n";
}

$author .= '</cite><!--/.author-->' . "\n";
Expand All @@ -134,8 +137,8 @@ function woothemes_testimonials ( $args = '' ) {
$template = str_replace( '%%ID%%', get_the_ID(), $template );
$template = str_replace( '%%CLASS%%', esc_attr( $css_class ), $template );

if ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] && ( '' != $post->url ) ) {
$template = str_replace( '%%AVATAR%%', '<a href="' . esc_url( $post->url ) . '" class="avatar-link">' . $post->image . '</a>', $template );
if ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] && ( '' != $author_url ) ) {
$template = str_replace( '%%AVATAR%%', '<a href="' . esc_url( $author_url ) . '" class="avatar-link">' . $post->image . '</a>', $template );
} elseif ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] ) {
$template = str_replace( '%%AVATAR%%', $post->image, $template );
} else {
Expand All @@ -156,6 +159,7 @@ function woothemes_testimonials ( $args = '' ) {
if( is_numeric( $args['per_row'] ) && ( $args['per_row'] > 0 ) && ( 0 == $count % $args['per_row'] ) ) {
$html .= '<div class="fix"></div>' . "\n";
}
$html .= woothemes_testimonials_generate_ld_json( $post );
}

wp_reset_postdata();
Expand All @@ -175,7 +179,6 @@ function woothemes_testimonials ( $args = '' ) {

// Allow child themes/plugins to filter here.
$html = apply_filters( 'woothemes_testimonials_html', $html, $query, $args );

if ( $args['echo'] != true ) { return $html; }

// Should only run is "echo" is set to true.
Expand All @@ -194,7 +197,7 @@ function woothemes_testimonials ( $args = '' ) {
* @return string Output using the template tag.
*/
function woothemes_testimonials_shortcode ( $atts, $content = null ) {
$args = (array)$atts;
$args = (array) $atts;

$defaults = array(
'limit' => 5,
Expand Down Expand Up @@ -248,4 +251,74 @@ function woothemes_testimonials_content_default_filters () {
} // End woothemes_testimonials_content_default_filters()

add_action( 'woothemes_testimonials_before', 'woothemes_testimonials_content_default_filters' );
}
}

/**
* Generates LD+JSON markup for testimonials.
*
* Generates LD+JSON markup for testimonials.
*
* @since 1.6.0
* @param WP_Post $post A WP_Post object.
* @return string $ld_json_output The JSON+LD markup.
*/
function woothemes_testimonials_generate_ld_json( $post ) {
$byline = get_post_meta( $post->ID, '_byline', true );
$author_url = esc_url( get_post_meta( $post->ID, '_url', true ) );
$post_title = get_the_title( $post );
$post_permalink = esc_url( get_post_permalink( $post->ID ) );
$post_published_date = str_replace( ' ', 'T', $post->post_date_gmt );
$language = get_bloginfo( 'language' );
$organization = get_bloginfo( 'name' );
$organization_url = esc_url( get_bloginfo( 'url' ) );
$content = wp_strip_all_tags( apply_filters( 'the_content', $post->post_content ), true );
$ld_json_output = <<<EOD
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Review",
"author": {
"@type": "Person",
"name": "$post_title",
"jobTitle": "$byline",
"sameAs": "$author_url"
},
"url": "$post_permalink",
"datePublished": "$post_published_date",
"description": "$content",
"inLanguage": "$language",
"itemReviewed": {
"@type": "Organization",
"name": "$organization",
"sameAs": "$organization_url",
"telephone": "+5511975414069"
},
"reviewRating": {
"@type": "Rating",
"worstRating": 1,
"bestRating": 5,
"ratingValue": 5
}
}
</script>
EOD;
return $ld_json_output;
}

/**
* Adds LD+JSON markup for single testimonials.
*
* Adds LD+JSON markup for single testimonials.
*
* @since 1.6.0
* @param WP_Post $post A WP_Post object.
* @return string $ld_json_output The JSON+LD markup.
*/
function woothemes_testimonials_single_post_ld_json() {
if ( ! is_singular( 'testimonial' ) ) {
return;
}
global $post;
echo woothemes_testimonials_generate_ld_json( $post ); // WPCS: XSS ok.
}
add_action( 'wp_head', 'woothemes_testimonials_single_post_ld_json' );