Yasr – Yet Another Stars Rating - Version 0.9.8

Version Description

  • TWEAKED: All the schema info use now json-ld and not microdata anymore. There is no need anymore to the sentence of the end of post :)
  • FIXED: itemtype selection
  • FIXED: itemtype if not rating
  • FIXED: RTL support, thank's to Arik Numlock
Download this release

Release Info

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

Code changes from version 0.9.7 to 0.9.8

css/yasr.css CHANGED
@@ -84,6 +84,24 @@
84
  background-color: #F7F7F7;
85
  }
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  /*
88
  IMAGES BY: Oxygen Team
89
  */
84
  background-color: #F7F7F7;
85
  }
86
 
87
+
88
+ /*** RTL RULES, thank's to Arik Numlock ***/
89
+
90
+ .rateit .rateit-hover.rateit-hover-rtl, .rateit .rateit-selected.rateit-selected-rtl {
91
+
92
+ -moz-transform: scaleX(-1);
93
+ -o-transform: scaleX(-1);
94
+
95
+ -webkit-transform: scaleX(-1);
96
+ transform: scaleX(-1);
97
+ filter: FlipH;
98
+ -ms-filter: “FlipH”;
99
+ right: 0;
100
+ left: auto;
101
+
102
+ }
103
+
104
+
105
  /*
106
  IMAGES BY: Oxygen Team
107
  */
lib/yasr-ajax-functions.php CHANGED
@@ -76,7 +76,7 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
76
  'overall_rating' => $rating,
77
  'review_type' => 'Product' //default review type in a new post
78
  ),
79
- array('%d', '%s', '%d', '%s')
80
  );
81
 
82
  $snippet_type = yasr_get_snippet_type();
@@ -167,21 +167,20 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
167
  );
168
 
169
  //if fail there is no row so make new one
170
- if($review_type === FALSE) {
171
 
172
- $review_type = $wpdb->replace(
173
  YASR_VOTES_TABLE,
174
  array (
175
  'post_id' => $post_id,
176
- 'overall_rating' => '-1',
177
  'review_type' => $reviewtype
178
  ),
179
- array('%s', '%s')
180
  );
181
 
182
  }
183
 
184
- if($review_type || $reviewtype !== FALSE) {
185
  _e("$reviewtype selected", "yasr");
186
  }
187
  else {
76
  'overall_rating' => $rating,
77
  'review_type' => 'Product' //default review type in a new post
78
  ),
79
+ array('%d', '%s', '%s')
80
  );
81
 
82
  $snippet_type = yasr_get_snippet_type();
167
  );
168
 
169
  //if fail there is no row so make new one
170
+ if($review_type === 0) {
171
 
172
+ $review_type = $wpdb->insert(
173
  YASR_VOTES_TABLE,
174
  array (
175
  'post_id' => $post_id,
 
176
  'review_type' => $reviewtype
177
  ),
178
+ array('%d', '%s')
179
  );
180
 
181
  }
182
 
183
+ if($review_type) {
184
  _e("$reviewtype selected", "yasr");
185
  }
186
  else {
lib/yasr-db-functions.php CHANGED
@@ -177,14 +177,14 @@ function yasr_get_snippet_type() {
177
 
178
  else {
179
 
180
- $result=$wpdb->get_results($wpdb->prepare("SELECT review_type FROM " . YASR_VOTES_TABLE . " WHERE post_id=%d", $post_id));
181
 
182
  if($result) {
183
  foreach ($result as $snippet) {
184
- $snippet_type = $snippet->review_type;
185
  }
186
 
187
- if ($snippet_type != 'Product' || $snippet_type != 'Place' || $snippet_type != 'Other') {
188
 
189
  $snippet_type = YASR_ITEMTYPE;
190
 
@@ -198,7 +198,7 @@ function yasr_get_snippet_type() {
198
 
199
  }
200
 
201
- return trim($snippet_type);
202
 
203
  }
204
 
177
 
178
  else {
179
 
180
+ $result=$wpdb->get_results($wpdb->prepare("SELECT review_type FROM " . YASR_VOTES_TABLE . " WHERE post_id=%d", $post_id));
181
 
182
  if($result) {
183
  foreach ($result as $snippet) {
184
+ $snippet_type = trim($snippet->review_type);
185
  }
186
 
187
+ if ($snippet_type != 'Product' && $snippet_type != 'Place' && $snippet_type != 'Other') {
188
 
189
  $snippet_type = YASR_ITEMTYPE;
190
 
198
 
199
  }
200
 
201
+ return $snippet_type;
202
 
203
  }
204
 
lib/yasr-functions.php CHANGED
@@ -280,10 +280,14 @@ 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();
@@ -294,38 +298,50 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
294
 
295
  global $post;
296
 
297
- $div = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Review\">";
298
 
299
- $author = "<span itemprop=\"author\" itemscope itemtype=\"http://schema.org/Person\"> " . __('reviewed by', 'yasr') . " <span itemprop=\"name\"> " . get_the_author() . " </span></span>";
300
 
301
- $date = __(' on ', 'yasr') . "<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date();
302
 
303
- $title = NULL; //avoid undefined
 
304
 
305
- if ($review_choosen == "Place") {
306
- $title = "<span itemprop=\"itemReviewed\" itemscope itemtype=\"http://schema.org/LocalBusiness\"> <span itemprop=\"name\"> ". get_the_title() ." </span></span>";
307
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
- elseif ($review_choosen == "Product") {
310
- $title = "<span itemprop=\"itemReviewed\" itemscope itemtype=\"http://schema.org/Product\"> <span itemprop=\"name\"> ". get_the_title() ." </span></span>";
311
  }
312
 
313
- elseif ($review_choosen == "Other") {
314
- $title = "<span itemprop=\"itemReviewed\" itemscope itemType=\"http://schema.org/BlogPosting\"> <span itemprop=\"name headline\"> ". get_the_title() ." </span>";
315
- $date =__('reviewed on', 'yasr') . " <meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date() . " </span>";
316
- $author = __('by ', 'yasr') . "<span itemprop=\"author\" itemscope itemtype=\"http://schema.org/Person\"><span itemprop=\"name\"> " . get_the_author() . " </span></span>";
317
 
318
  }
319
 
320
- $rating = "<span itemprop=\"reviewRating\" itemscope itemtype=\"http://schema.org/Rating\"> ". __( 'rated' , 'yasr' ) . " <span itemprop=\"ratingValue\">" . $overall_rating . "</span> " . __('of', 'yasr') ." <span itemprop=\"bestRating\"> 5 </span></span>";
321
- $end_div= "</div>";
322
 
 
323
 
324
- $schema = $div . $title . $author . $date . $rating . $end_div;
325
 
326
- if ($review_choosen == "Other") {
327
 
328
- $schema = $div . $title . $date . $author . $rating . $end_div;
329
 
330
  }
331
 
@@ -357,39 +373,54 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
357
 
358
  $average_rating = $visitor_rating['sum'] / $visitor_rating['votes_number'];
359
 
360
- $average_rating=round($average_rating, 1);
361
 
362
- if ($review_choosen == 'Place') {
363
- $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/LocalBusiness\"> <span itemprop=\"name\">". get_the_title() ."</span>";
364
- $date = '';
365
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
 
367
- if ($review_choosen == 'Other') {
368
- $div_1 = "<div class=\"yasr_schema\" itemscope itemType=\"http://schema.org/BlogPosting\"><span itemprop=\"name headline\">". get_the_title() ."</span>";
369
- $date = __(' on ', 'yasr') . "<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date();
370
  }
371
 
372
- elseif ($review_choosen == "Product") {
373
- $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Product\"><span itemprop=\"name\">". get_the_title() ."</span>";
374
- $date = '';
 
375
  }
376
 
377
- $author = __( ' written by ' , 'yasr' ) . get_the_author();
378
-
379
- $span_1 = "<span itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\">";
380
- $rating = __( ' average rating ' , 'yasr' ) . "<span itemprop=\"ratingValue\">" . $average_rating . "</span>/<span itemprop=\"bestRating\">5</span>";
381
- $n_ratings = " - <span itemprop=\"ratingCount\"> " . $visitor_rating['votes_number'] . "</span>" . __(' user ratings', 'yasr');
382
- $end_span_1 = "</span>";
383
- $end_div_1 = "</div>";
384
 
385
- $schema = $div_1 . $author . $date . $span_1 . $rating . $n_ratings . $end_span_1 . $end_div_1;
 
 
 
 
 
 
 
 
386
 
387
  }
388
 
389
  }
390
 
391
  if ( is_singular() && is_main_query() && !is_404() ) {
392
- return $content . $schema;
393
  }
394
 
395
  else {
@@ -432,8 +463,6 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
432
  echo "<option value=\"$i\">$type</option>";
433
  }
434
 
435
- //echo $review_type_choosen . '&nbsp;' . $type . '<br />';
436
-
437
  $i = $i+1;
438
 
439
  }
280
 
281
  }
282
 
283
+ $script_type = '<script type="application/ld+json">';
284
+
285
+ $end_script_type = '</script>';
286
 
287
  $review_choosen = yasr_get_snippet_type();
288
 
289
+ $rich_snippet["@context"] = "http://schema.org/";
290
+
291
  if (YASR_SNIPPET == 'overall_rating') {
292
 
293
  $overall_rating=yasr_get_overall_rating();
298
 
299
  global $post;
300
 
301
+ $author = get_the_author();
302
 
303
+ $review_name = get_the_title();
304
 
305
+ $date = get_the_date('c');
306
 
307
+ //name
308
+ $rich_snippet["name"]= $review_name;
309
 
310
+ $rich_snippet["Review"] = array (
311
+ "@type" => "Review",
312
+ "name" => "$review_name",
313
+ "author" => array(
314
+ "@type" => "Person",
315
+ "name" => "$author"
316
+ ),
317
+ "datePublished" => "$date",
318
+ "reviewRating" => array(
319
+ "@type" => "Rating",
320
+ "ratingValue" => "$overall_rating",
321
+ ),
322
+ );
323
+
324
+ if ($review_choosen == "Product") {
325
+
326
+ $rich_snippet["@type"]="Product";
327
 
 
 
328
  }
329
 
330
+ elseif ($review_choosen == "Place") {
331
+
332
+ $rich_snippet["@type"]="LocalBusiness";
 
333
 
334
  }
335
 
336
+ elseif ($review_choosen == "Other") {
 
337
 
338
+ $rich_snippet["@type"] = "BlogPosting";
339
 
340
+ $rich_snippet["datePublished"] = $date;
341
 
342
+ $rich_snippet["headline"] = $review_name;
343
 
344
+ $rich_snippet["image"] = wp_get_attachment_url(get_post_thumbnail_id());
345
 
346
  }
347
 
373
 
374
  $average_rating = $visitor_rating['sum'] / $visitor_rating['votes_number'];
375
 
376
+ $average_rating = round($average_rating, 1);
377
 
378
+ $author = get_the_author();
379
+
380
+ $review_name = get_the_title();
381
+
382
+ $date = get_the_date('c');
383
+
384
+ //name
385
+ $rich_snippet["name"] = $review_name;
386
+
387
+ $rich_snippet["aggregateRating"] = array (
388
+ "@type" => "AggregateRating",
389
+ "ratingValue" => "$average_rating",
390
+ "ratingCount" => $visitor_rating['votes_number'],
391
+ );
392
+
393
+
394
+ if ($review_choosen == "Product") {
395
+
396
+ $rich_snippet["@type"] = "Product";
397
 
 
 
 
398
  }
399
 
400
+ elseif ($review_choosen == "Place") {
401
+
402
+ $rich_snippet["@type"] = "LocalBusiness";
403
+
404
  }
405
 
406
+ elseif ($review_choosen == "Other") {
 
 
 
 
 
 
407
 
408
+ $rich_snippet["@type"] = "BlogPosting";
409
+
410
+ $rich_snippet["datePublished"] = $date;
411
+
412
+ $rich_snippet["headline"] = $review_name;
413
+
414
+ $rich_snippet["image"] = wp_get_attachment_url(get_post_thumbnail_id());
415
+
416
+ }
417
 
418
  }
419
 
420
  }
421
 
422
  if ( is_singular() && is_main_query() && !is_404() ) {
423
+ return $content . $script_type . json_encode($rich_snippet) . $end_script_type;
424
  }
425
 
426
  else {
463
  echo "<option value=\"$i\">$type</option>";
464
  }
465
 
 
 
466
  $i = $i+1;
467
 
468
  }
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.1
7
- Stable tag: 0.9.7
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,12 @@ Of course not: you can easily add it on the visual editor just by clicking on th
123
 
124
  == Changelog ==
125
 
 
 
 
 
 
 
126
  = 0.9.7 =
127
  * FIXED: bug with itemtype if yasr is not used in English
128
  * NEW FEATURE: in the settings, is now possible to choose the default itemtype for all posts/pages
4
  Requires at least: 3.5
5
  Contributors: Dudo
6
  Tested up to: 4.3.1
7
+ Stable tag: 0.9.8
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.8 =
127
+ * TWEAKED: All the schema info use now json-ld and not microdata anymore. There is no need anymore to the sentence of the end of post :)
128
+ * FIXED: itemtype selection
129
+ * FIXED: itemtype if not rating
130
+ * FIXED: RTL support, thank's to Arik Numlock
131
+
132
  = 0.9.7 =
133
  * FIXED: bug with itemtype if yasr is not used in English
134
  * NEW FEATURE: in the settings, is now possible to choose the default itemtype for all posts/pages
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.7
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.7');
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.8
7
  * Author: Dario Curvino
8
  * Author URI: https://yetanotherstarsrating.com/
9
  * License: GPL2
28
  */
29
 
30
 
31
+ define('YASR_VERSION_NUM', '0.9.8');
32
 
33
  //Plugin relative path
34
  define( "YASR_RELATIVE_PATH", dirname(__FILE__) );