Yasr – Yet Another Stars Rating - Version 0.9.5

Version Description

  • Fixed div not created if schema info not present
Download this release

Release Info

Developer Dudo
Plugin Icon 128x128 Yasr – Yet Another Stars Rating
Version 0.9.5
Comparing to
See all releases

Code changes from version 0.9.4 to 0.9.5

lib/yasr-functions.php CHANGED
@@ -264,7 +264,11 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
264
 
265
  add_filter('the_content', 'yasr_add_schema');
266
 
267
- function yasr_add_schema($content) {
 
 
 
 
268
 
269
  //Add buddypress compatibility
270
  if (function_exists('bp_is_active')) {
@@ -280,18 +284,18 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
280
 
281
  }
282
 
283
- $schema=NULL; //To avoid undefined variable notice outside the loop
284
 
285
  $review_choosen = yasr_get_snippet_type();
286
 
287
- if (YASR_SNIPPET == 'overall_rating') {
288
 
289
- $overall_rating=yasr_get_overall_rating();
290
 
291
- if($overall_rating && $overall_rating != '-1' && $overall_rating != '0.0') {
292
 
293
- if(is_singular() && is_main_query() ) {
294
- global $post;
295
 
296
  $div = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Review\">";
297
 
@@ -309,7 +313,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
309
  $title = "<span itemprop=\"itemReviewed\" itemscope itemtype=\"http://schema.org/Product\"> <span itemprop=\"name\">". get_the_title() ."</span></span>";
310
  }
311
 
312
- elseif ($review_choosen == "Other") {
313
  $title = "<span itemprop=\"itemReviewed\" itemscope itemType=\"http://schema.org/BlogPosting\"> <span itemprop=\"name headline\">". get_the_title() ." </span>";
314
  $date =__('reviewed on', 'yasr')."<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date() . " </span>";
315
  $author = "<span itemprop=\"author\" itemscope itemtype=\"http://schema.org/Person\">" . __('by ', 'yasr') . "<span itemprop=\"name\">" . get_the_author() . "</span></span>";
@@ -329,15 +333,15 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
329
  }
330
 
331
 
332
- }
333
 
334
- } //END id if $overall_rating != '-1'
335
 
336
- } //end if ($choosen_snippet['snippet'] == 'overall_rating')
337
 
338
- if (YASR_SNIPPET == 'visitor_rating') {
339
 
340
- $visitor_votes = yasr_get_visitor_votes ();
341
 
342
  if ($visitor_votes) {
343
 
@@ -352,11 +356,11 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
352
  $visitor_rating = NULL;
353
  }
354
 
355
- if ($visitor_rating['sum'] != 0 && $visitor_rating['votes_number'] != 0) {
356
 
357
- $average_rating = $visitor_rating['sum'] / $visitor_rating['votes_number'];
358
 
359
- $average_rating=round($average_rating, 1);
360
 
361
  if ($review_choosen == 'Place') {
362
  $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/LocalBusiness\"> <span itemprop=\"name\">". get_the_title() ."</span>";
@@ -368,7 +372,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
368
  $date = __(' on ', 'yasr') . "<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date();
369
  }
370
 
371
- elseif ($review_choosen == "Product") {
372
  $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Product\"><span itemprop=\"name\">". get_the_title() ."</span>";
373
  $date = '';
374
  }
264
 
265
  add_filter('the_content', 'yasr_add_schema');
266
 
267
+ /****** Add review schema data at the end of the post *******/
268
+
269
+ add_filter('the_content', 'yasr_add_schema');
270
+
271
+ function yasr_add_schema($content) {
272
 
273
  //Add buddypress compatibility
274
  if (function_exists('bp_is_active')) {
284
 
285
  }
286
 
287
+ $schema=NULL; //To avoid undefined variable notice outside the loop
288
 
289
  $review_choosen = yasr_get_snippet_type();
290
 
291
+ if (YASR_SNIPPET == 'overall_rating') {
292
 
293
+ $overall_rating=yasr_get_overall_rating();
294
 
295
+ if($overall_rating && $overall_rating != '-1' && $overall_rating != '0.0') {
296
 
297
+ if(is_singular() && is_main_query() ) {
298
+ global $post;
299
 
300
  $div = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Review\">";
301
 
313
  $title = "<span itemprop=\"itemReviewed\" itemscope itemtype=\"http://schema.org/Product\"> <span itemprop=\"name\">". get_the_title() ."</span></span>";
314
  }
315
 
316
+ elseif ($review_choosen == "Product" || !$review_choosen) {
317
  $title = "<span itemprop=\"itemReviewed\" itemscope itemType=\"http://schema.org/BlogPosting\"> <span itemprop=\"name headline\">". get_the_title() ." </span>";
318
  $date =__('reviewed on', 'yasr')."<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date() . " </span>";
319
  $author = "<span itemprop=\"author\" itemscope itemtype=\"http://schema.org/Person\">" . __('by ', 'yasr') . "<span itemprop=\"name\">" . get_the_author() . "</span></span>";
333
  }
334
 
335
 
336
+ }
337
 
338
+ } //END id if $overall_rating != '-1'
339
 
340
+ } //end if ($choosen_snippet['snippet'] == 'overall_rating')
341
 
342
+ if (YASR_SNIPPET == 'visitor_rating') {
343
 
344
+ $visitor_votes = yasr_get_visitor_votes ();
345
 
346
  if ($visitor_votes) {
347
 
356
  $visitor_rating = NULL;
357
  }
358
 
359
+ if ($visitor_rating['sum'] != 0 && $visitor_rating['votes_number'] != 0) {
360
 
361
+ $average_rating = $visitor_rating['sum'] / $visitor_rating['votes_number'];
362
 
363
+ $average_rating=round($average_rating, 1);
364
 
365
  if ($review_choosen == 'Place') {
366
  $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/LocalBusiness\"> <span itemprop=\"name\">". get_the_title() ."</span>";
372
  $date = __(' on ', 'yasr') . "<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date();
373
  }
374
 
375
+ elseif ($review_choosen == "Product" || !$review_choosen) {
376
  $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Product\"><span itemprop=\"name\">". get_the_title() ."</span>";
377
  $date = '';
378
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: 5 star, admin, administrator, AJAX, five-star, javascript, jquery, post r
4
  Requires at least: 3.5
5
  Contributors: Dudo
6
  Tested up to: 4.3
7
- Stable tag: 0.9.4
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  Yet Another Stars Rating is a simple plugin which allows you and / or your visitor to rate a post or element. Ideal for review's website
@@ -123,6 +123,9 @@ Of course not: you can easily add it on the visual editor just by clicking on th
123
 
124
  == Changelog ==
125
 
 
 
 
126
  = 0.9.4 =
127
  * FIXED: all the ratings for a post or page get reset if choosen again the current schema type
128
  * FIXED: Schema errors
4
  Requires at least: 3.5
5
  Contributors: Dudo
6
  Tested up to: 4.3
7
+ Stable tag: 0.9.5
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  Yet Another Stars Rating is a simple plugin which allows you and / or your visitor to rate a post or element. Ideal for review's website
123
 
124
  == Changelog ==
125
 
126
+ = 0.9.5 =
127
+ * Fixed div not created if schema info not present
128
+
129
  = 0.9.4 =
130
  * FIXED: all the ratings for a post or page get reset if choosen again the current schema type
131
  * FIXED: Schema errors
yet-another-stars-rating.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Yet Another Stars Rating
4
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
5
  * Description: Rating system with rich snippets
6
- * Version: 0.9.4
7
  * Author: Dario Curvino
8
  * Author URI: https://yetanotherstarsrating.com/
9
  * License: GPL2
@@ -28,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
28
  */
29
 
30
 
31
- define('YASR_VERSION_NUM', '0.9.4');
32
 
33
  //Plugin relative path
34
  define( "YASR_RELATIVE_PATH", dirname(__FILE__) );
3
  * Plugin Name: Yet Another Stars Rating
4
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
5
  * Description: Rating system with rich snippets
6
+ * Version: 0.9.5
7
  * Author: Dario Curvino
8
  * Author URI: https://yetanotherstarsrating.com/
9
  * License: GPL2
28
  */
29
 
30
 
31
+ define('YASR_VERSION_NUM', '0.9.5');
32
 
33
  //Plugin relative path
34
  define( "YASR_RELATIVE_PATH", dirname(__FILE__) );