Yasr – Yet Another Stars Rating - Version 0.9.9

Version Description

  • New feature: is now possible to choose between json-ld and microdata for rich snippet
Download this release

Release Info

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

Code changes from version 0.9.8 to 0.9.9

lib/yasr-db-functions.php CHANGED
@@ -109,6 +109,7 @@ function yasr_install() {
109
$option['text_before_stars'] = 0;
110
$option['snippet'] = 'overall_rating';
111
$option['snippet_itemtype'] = 'Product';
112
$option['allowed_user'] = 'allow_anonymous';
113
$option['metabox_overall_rating'] = 'stars'; //This is not in settings page but in overall rating metabox
114
$option['visitors_stats'] = 'yes';
109
$option['text_before_stars'] = 0;
110
$option['snippet'] = 'overall_rating';
111
$option['snippet_itemtype'] = 'Product';
112
+ $option['snippet_format'] = 'microdata';
113
$option['allowed_user'] = 'allow_anonymous';
114
$option['metabox_overall_rating'] = 'stars'; //This is not in settings page but in overall rating metabox
115
$option['visitors_stats'] = 'yes';
lib/yasr-functions.php CHANGED
@@ -280,151 +280,280 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
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();
294
295
- if($overall_rating && $overall_rating != '-1' && $overall_rating != '0.0') {
296
297
- if(is_singular() && is_main_query() ) {
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
-
348
349
- }
350
351
- } //END id if $overall_rating != '-1'
352
353
- } //end if ($choosen_snippet['snippet'] == 'overall_rating')
354
355
- if (YASR_SNIPPET == 'visitor_rating') {
356
357
- $visitor_votes = yasr_get_visitor_votes ();
358
359
- if ($visitor_votes) {
360
361
- foreach ($visitor_votes as $rating) {
362
- $visitor_rating['votes_number']=$rating->number_of_votes;
363
- $visitor_rating['sum']=$rating->sum_votes;
364
}
365
366
}
367
368
- else {
369
- $visitor_rating = NULL;
370
}
371
372
- if ($visitor_rating['sum'] != 0 && $visitor_rating['votes_number'] != 0) {
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 {
427
- return $content;
428
}
429
430
280
281
}
282
283
+ //if is not jsonld (default case)
284
+ if(YASR_SCHEMA_FORMAT != 'jsonld'){
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
299
+ global $post;
300
301
+ $div = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Review\">";
302
303
+ $author = "<span itemprop=\"author\" itemscope itemtype=\"http://schema.org/Person\"> " . __('reviewed by', 'yasr') . " <span itemprop=\"name\"> " . get_the_author() . " </span></span>";
304
305
+ $date = __(' on ', 'yasr') . "<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date();
306
307
+ $title = NULL; //avoid undefined
308
309
+ if ($review_choosen == "Place") {
310
+ $title = "<span itemprop=\"itemReviewed\" itemscope itemtype=\"http://schema.org/LocalBusiness\"> <span itemprop=\"name\"> ". get_the_title() ." </span></span>";
311
+ }
312
313
+ elseif ($review_choosen == "Product") {
314
+ $title = "<span itemprop=\"itemReviewed\" itemscope itemtype=\"http://schema.org/Product\"> <span itemprop=\"name\"> ". get_the_title() ." </span></span>";
315
+ }
316
317
+ elseif ($review_choosen == "Other") {
318
+ $title = "<span itemprop=\"itemReviewed\" itemscope itemType=\"http://schema.org/BlogPosting\"> <span itemprop=\"name headline\"> ". get_the_title() ." </span>";
319
+ $date =__('reviewed on', 'yasr') . " <meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date() . " </span>";
320
+ $author = __('by ', 'yasr') . "<span itemprop=\"author\" itemscope itemtype=\"http://schema.org/Person\"><span itemprop=\"name\"> " . get_the_author() . " </span></span>";
321
322
+ }
323
+
324
+ $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>";
325
+ $end_div= "</div>";
326
+
327
+
328
+ $schema = $div . $title . $author . $date . $rating . $end_div;
329
+
330
+ if ($review_choosen == "Other") {
331
+
332
+ $schema = $div . $title . $date . $author . $rating . $end_div;
333
334
+ }
335
+
336
337
}
338
339
+ } //END id if $overall_rating != '-1'
340
341
+ } //end if ($choosen_snippet['snippet'] == 'overall_rating')
342
343
+ if (YASR_SNIPPET == 'visitor_rating') {
344
345
+ $visitor_votes = yasr_get_visitor_votes ();
346
347
+ if ($visitor_votes) {
348
349
+ foreach ($visitor_votes as $rating) {
350
+ $visitor_rating['votes_number']=$rating->number_of_votes;
351
+ $visitor_rating['sum']=$rating->sum_votes;
352
}
353
354
+ }
355
356
+ else {
357
+ $visitor_rating = NULL;
358
+ }
359
+
360
+ if ($visitor_rating['sum'] != 0 && $visitor_rating['votes_number'] != 0) {
361
362
+ $average_rating = $visitor_rating['sum'] / $visitor_rating['votes_number'];
363
364
+ $average_rating=round($average_rating, 1);
365
366
+ if ($review_choosen == 'Place') {
367
+ $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/LocalBusiness\"> <span itemprop=\"name\">". get_the_title() ."</span>";
368
+ $date = '';
369
+ }
370
371
+ if ($review_choosen == 'Other') {
372
+ $div_1 = "<div class=\"yasr_schema\" itemscope itemType=\"http://schema.org/BlogPosting\"><span itemprop=\"name headline\">". get_the_title() ."</span>";
373
+ $date = __(' on ', 'yasr') . "<meta itemprop=\"datePublished\" content=\"" . get_the_date('c') . "\"> " . get_the_date();
374
+ }
375
+
376
+ elseif ($review_choosen == "Product") {
377
+ $div_1 = "<div class=\"yasr_schema\" itemscope itemtype=\"http://schema.org/Product\"><span itemprop=\"name\">". get_the_title() ."</span>";
378
+ $date = '';
379
+ }
380
+
381
+ $author = __( ' written by ' , 'yasr' ) . get_the_author();
382
+
383
+ $span_1 = "<span itemprop=\"aggregateRating\" itemscope itemtype=\"http://schema.org/AggregateRating\">";
384
+ $rating = __( ' average rating ' , 'yasr' ) . "<span itemprop=\"ratingValue\">" . $average_rating . "</span>/<span itemprop=\"bestRating\">5</span>";
385
+ $n_ratings = " - <span itemprop=\"ratingCount\"> " . $visitor_rating['votes_number'] . "</span>" . __(' user ratings', 'yasr');
386
+ $end_span_1 = "</span>";
387
+ $end_div_1 = "</div>";
388
+
389
+ $schema = $div_1 . $author . $date . $span_1 . $rating . $n_ratings . $end_span_1 . $end_div_1;
390
391
}
392
393
}
394
395
+ if ( is_singular() && is_main_query() && !is_404() ) {
396
+ return $content . $schema;
397
}
398
399
+ else {
400
+ return $content;
401
+ }
402
403
404
+ } //End if(YASR_SCHEMA_FORMAT != 'jsonld'){
405
406
407
+ //if is jsonld
408
+ else {
409
410
+ $script_type = '<script type="application/ld+json">';
411
412
+ $end_script_type = '</script>';
413
414
+ $review_choosen = yasr_get_snippet_type();
415
416
+ $rich_snippet["@context"] = "http://schema.org/";
417
418
+ if (YASR_SNIPPET == 'overall_rating') {
419
420
+ $overall_rating=yasr_get_overall_rating();
421
+
422
+ if($overall_rating && $overall_rating != '-1' && $overall_rating != '0.0') {
423
+
424
+ if(is_singular() && is_main_query() ) {
425
+
426
+ global $post;
427
+
428
+ $author = get_the_author();
429
+
430
+ $review_name = get_the_title();
431
+
432
+ $date = get_the_date('c');
433
+
434
+ //name
435
+ $rich_snippet["name"]= $review_name;
436
+
437
+ $rich_snippet["Review"] = array (
438
+ "@type" => "Review",
439
+ "name" => "$review_name",
440
+ "author" => array(
441
+ "@type" => "Person",
442
+ "name" => "$author"
443
+ ),
444
+ "datePublished" => "$date",
445
+ "reviewRating" => array(
446
+ "@type" => "Rating",
447
+ "ratingValue" => "$overall_rating",
448
+ ),
449
+ );
450
+
451
+ if ($review_choosen == "Product") {
452
+
453
+ $rich_snippet["@type"]="Product";
454
+
455
+ }
456
+
457
+ elseif ($review_choosen == "Place") {
458
+
459
+ $rich_snippet["@type"]="LocalBusiness";
460
+
461
+ }
462
+
463
+ elseif ($review_choosen == "Other") {
464
465
+ $rich_snippet["@type"] = "BlogPosting";
466
467
+ $rich_snippet["datePublished"] = $date;
468
469
+ $rich_snippet["headline"] = $review_name;
470
+
471
+ $rich_snippet["image"] = wp_get_attachment_url(get_post_thumbnail_id());
472
+
473
+ }
474
+
475
+
476
+ }
477
+
478
+ } //END id if $overall_rating != '-1'
479
+
480
+ } //end if ($choosen_snippet['snippet'] == 'overall_rating')
481
+
482
+ if (YASR_SNIPPET == 'visitor_rating') {
483
+
484
+ $visitor_votes = yasr_get_visitor_votes ();
485
+
486
+ if ($visitor_votes) {
487
+
488
+ foreach ($visitor_votes as $rating) {
489
+ $visitor_rating['votes_number']=$rating->number_of_votes;
490
+ $visitor_rating['sum']=$rating->sum_votes;
491
+ }
492
+
493
+ }
494
+
495
+ else {
496
+ $visitor_rating = NULL;
497
}
498
499
+ if ($visitor_rating['sum'] != 0 && $visitor_rating['votes_number'] != 0) {
500
501
+ $average_rating = $visitor_rating['sum'] / $visitor_rating['votes_number'];
502
503
+ $average_rating = round($average_rating, 1);
504
+
505
+ $author = get_the_author();
506
507
+ $review_name = get_the_title();
508
+
509
+ $date = get_the_date('c');
510
+
511
+ //name
512
+ $rich_snippet["name"] = $review_name;
513
+
514
+ $rich_snippet["aggregateRating"] = array (
515
+ "@type" => "AggregateRating",
516
+ "ratingValue" => "$average_rating",
517
+ "ratingCount" => $visitor_rating['votes_number'],
518
+ );
519
+
520
+
521
+ if ($review_choosen == "Product") {
522
523
+ $rich_snippet["@type"] = "Product";
524
+
525
+ }
526
+
527
+ elseif ($review_choosen == "Place") {
528
+
529
+ $rich_snippet["@type"] = "LocalBusiness";
530
+
531
+ }
532
+
533
+ elseif ($review_choosen == "Other") {
534
+
535
+ $rich_snippet["@type"] = "BlogPosting";
536
+
537
+ $rich_snippet["datePublished"] = $date;
538
+
539
+ $rich_snippet["headline"] = $review_name;
540
+
541
+ $rich_snippet["image"] = wp_get_attachment_url(get_post_thumbnail_id());
542
+
543
+ }
544
545
}
546
547
}
548
549
+ if ( is_singular() && is_main_query() && !is_404() ) {
550
+ return $content . $script_type . json_encode($rich_snippet) . $end_script_type;
551
+ }
552
553
+ else {
554
+ return $content;
555
+ }
556
557
}
558
559
lib/yasr-settings-functions.php CHANGED
@@ -440,8 +440,30 @@ if ( ! defined( 'ABSPATH' ) ) exit('You\'re not allowed to see this page'); // E
440
<br />
441
<small><?php _e('This will affect only the post/page where you didn\'t change manually the itemtype yet.', 'yasr'); ?> </small>
442
443
</div>
444
445
<p>&nbsp;</p>
446
447
<hr>
440
<br />
441
<small><?php _e('This will affect only the post/page where you didn\'t change manually the itemtype yet.', 'yasr'); ?> </small>
442
443
+ <p>&nbsp;</p>
444
+
445
</div>
446
447
+
448
+ <strong><?php _e('Which format do you want to use?', 'yasr'); ?></strong>
449
+
450
+ <div class="yasr-indented-answer">
451
+ <input type="radio" name="yasr_general_options[snippet_format]" value="microdata" class="yasr_choose_snippet" <?php if ($option['snippet_format']==='microdata') echo " checked=\"checked\" "; ?> >
452
+ <?php _e('Microdata', 'yasr') ?>
453
+ <br />
454
+
455
+ <input type="radio" name="yasr_general_options[snippet_format]" value="jsonld" class="yasr_choose_snippet" <?php if ($option['snippet_format']==='jsonld') echo " checked=\"checked\" "; ?> >
456
+ <?php _e('Json-ld', 'yasr')?>
457
+ <br />
458
+
459
+ <br />
460
+
461
+ <small><?php _e('Leave the default value if you don\'t know what this is' , 'yasr'); ?></small>
462
+
463
+ <p>&nbsp;</p>
464
+
465
+ </div>
466
+
467
<p>&nbsp;</p>
468
469
<hr>
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.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,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.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
4
Requires at least: 3.5
5
Contributors: Dudo
6
Tested up to: 4.3.1
7
+ Stable tag: 0.9.9
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.9 =
127
+ * New feature: is now possible to choose between json-ld and microdata for rich snippet
128
+
129
= 0.9.8 =
130
* 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 :)
131
* FIXED: itemtype selection
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.8
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.8');
32
33
//Plugin relative path
34
define( "YASR_RELATIVE_PATH", dirname(__FILE__) );
@@ -52,6 +52,7 @@ define ("YASR_IMG_DIR", plugins_url( YASR_RELATIVE_PATH_PLUGIN_DIR . '/img/'));
52
53
/****** Getting options ******/
54
55
$stored_options = get_option( 'yasr_general_options' );
56
57
define ("YASR_AUTO_INSERT_ENABLED", $stored_options['auto_insert_enabled']);
@@ -93,6 +94,7 @@ define ("YASR_VISITORS_STATS", $stored_options['visitors_stats']);
93
define ("YASR_ALLOWED_USER", $stored_options['allowed_user']);
94
define ("YASR_SNIPPET", $stored_options['snippet']);
95
define ("YASR_ITEMTYPE", $stored_options['snippet_itemtype']);
96
define ("YASR_METABOX_OVERALL_RATING", $stored_options['metabox_overall_rating']);
97
98
@@ -162,6 +164,16 @@ define ("YASR_LOADER_IMAGE", YASR_IMG_DIR . "/loader.gif");
162
163
/****** backward compatibility functions ******/
164
165
//Remove end March 2016
166
if ($version_installed && $version_installed < '0.9.7') {
167
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.9
7
* Author: Dario Curvino
8
* Author URI: https://yetanotherstarsrating.com/
9
* License: GPL2
28
*/
29
30
31
+ define('YASR_VERSION_NUM', '0.9.9');
32
33
//Plugin relative path
34
define( "YASR_RELATIVE_PATH", dirname(__FILE__) );
52
53
/****** Getting options ******/
54
55
+ //Get general options
56
$stored_options = get_option( 'yasr_general_options' );
57
58
define ("YASR_AUTO_INSERT_ENABLED", $stored_options['auto_insert_enabled']);
94
define ("YASR_ALLOWED_USER", $stored_options['allowed_user']);
95
define ("YASR_SNIPPET", $stored_options['snippet']);
96
define ("YASR_ITEMTYPE", $stored_options['snippet_itemtype']);
97
+ define ("YASR_SCHEMA_FORMAT", $stored_options['snippet_format']);
98
define ("YASR_METABOX_OVERALL_RATING", $stored_options['metabox_overall_rating']);
99
100
164
165
/****** backward compatibility functions ******/
166
167
+ //Remove end April 2016
168
+ if ($version_installed && $version_installed < '0.9.9') {
169
+
170
+ $stored_options['snippet_format'] = 'microdata';
171
+
172
+ update_option("yasr_general_options", $stored_options);
173
+
174
+ }
175
+
176
+
177
//Remove end March 2016
178
if ($version_installed && $version_installed < '0.9.7') {
179