diff --git a/classes/class-woothemes-testimonials.php b/classes/class-woothemes-testimonials.php
index d2f47d4..65169c4 100644
--- a/classes/class-woothemes-testimonials.php
+++ b/classes/class-woothemes-testimonials.php
@@ -17,7 +17,7 @@ class Woothemes_Testimonials {
private $assets_dir;
private $assets_url;
private $token;
- public $version;
+ public $version;
private $file;
/**
@@ -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' ), '', '' ),
- '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' ), '', '' ),
+ '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()
/**
diff --git a/classes/class-woothemes-widget-testimonials.php b/classes/class-woothemes-widget-testimonials.php
index 53e022b..da807eb 100644
--- a/classes/class-woothemes-widget-testimonials.php
+++ b/classes/class-woothemes-widget-testimonials.php
@@ -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 );
-?>
\ No newline at end of file
+add_action( 'widgets_init', function() {
+ return register_widget( 'Woothemes_Widget_Testimonials' );
+}, 1 );
+?>
diff --git a/woothemes-testimonials-template.php b/woothemes-testimonials-template.php
index 91c6236..0c0388a 100644
--- a/woothemes-testimonials-template.php
+++ b/woothemes-testimonials-template.php
@@ -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.
@@ -85,11 +84,13 @@ function woothemes_testimonials ( $args = '' ) {
$html .= '
' . "\n";
// Begin templating logic.
- $tpl = '
%%TEXT%%
%%AVATAR%% %%AUTHOR%%
';
+ $tpl = '
%%TEXT%%
%%AVATAR%% %%AUTHOR%%
';
$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';
@@ -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 .= '
';
+ $post_title = get_the_title( $post );
+ $byline = $post->byline;
+ $author_url = esc_url( $post->url );
+ if ( ( $post_title != '' ) && true == $args['display_author'] ) {
+ $author .= '';
- $author_name = '' . get_the_title( $post ) . '';
+ $author_name = '' . $post_title . '';
$author .= $author_name;
- if ( isset( $post->byline ) && '' != $post->byline ) {
- $author .= ' ' . $post->byline . '' . "\n";
+ if ( isset( $byline ) && '' != $byline ) {
+ $author .= ' ' . $byline . '' . "\n";
}
- if ( true == $args['display_url'] && '' != $post->url ) {
- $author .= ' ' . apply_filters( 'woothemes_testimonials_author_link_text', $text = esc_url( $post->url ) ) . '' . "\n";
+ if ( true == $args['display_url'] && '' != $author_url ) {
+ $author .= ' ' . apply_filters( 'woothemes_testimonials_author_link_text', $text = esc_url( $author_url ) ) . '' . "\n";
}
$author .= '' . "\n";
@@ -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%%', '' . $post->image . '', $template );
+ if ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] && ( '' != $author_url ) ) {
+ $template = str_replace( '%%AVATAR%%', '' . $post->image . '', $template );
} elseif ( isset( $post->image ) && ( '' != $post->image ) && true == $args['display_avatar'] ) {
$template = str_replace( '%%AVATAR%%', $post->image, $template );
} else {
@@ -156,6 +159,7 @@ function woothemes_testimonials ( $args = '' ) {
if( is_numeric( $args['per_row'] ) && ( $args['per_row'] > 0 ) && ( 0 == $count % $args['per_row'] ) ) {
$html .= '' . "\n";
}
+ $html .= woothemes_testimonials_generate_ld_json( $post );
}
wp_reset_postdata();
@@ -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.
@@ -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,
@@ -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' );
-}
\ No newline at end of file
+}
+
+/**
+ * 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 = <<
+ {
+ "@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
+ }
+ }
+
+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' );