Yasr – Yet Another Stars Rating - Version 2.9.8

Version Description

  • TWEAKED: updated rest api
  • FIX: softwareApplication itemType didn't get saved
  • Fix: impossible to rate for overall rating in certain circumstances.
  • Fix: minor css fixes in admin area
Download this release

Release Info

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

Code changes from version 2.9.7 to 2.9.8

admin/css/yasr-admin.css CHANGED
@@ -516,6 +516,7 @@
516
  font-weight: 600;
517
  }
518
 
 
519
  .yasr-donate-single-resource{
520
  margin-bottom: 12px;
521
  padding-bottom: 4px;
516
  font-weight: 600;
517
  }
518
 
519
+
520
  .yasr-donate-single-resource{
521
  margin-bottom: 12px;
522
  padding-bottom: 4px;
admin/editor/YasrMetaboxSchemaFields.php CHANGED
@@ -220,23 +220,23 @@ class YasrMetaboxSchemaFields {
220
  $software_array = array(
221
  'application' => array(
222
  'label' => 'Application Category',
223
- 'name' => 'yasr_software_application',
224
  'description' => __('Type of software application, e.g. \'Game, Multimedia\'. ', 'yet-another-stars-rating')
225
  ),
226
  'os' => array(
227
  'label' => 'Operating System',
228
- 'name' => 'yasr_software_os',
229
- 'description' => __('Operating systems supported e.g. (Windows 7, OSX 10.6, Android 1.6)' , 'yet-another-stars-rating')
230
  )
231
  );
232
 
233
  $this->echoFields($software_array);
234
 
235
- $this->offer('yasr_software_price',
236
- 'yasr_software_price_currency',
237
- 'yasr_software_price_valid_until',
238
- 'yasr_software_price_availability',
239
- 'yasr_software_price_url');
240
 
241
  ?>
242
 
220
  $software_array = array(
221
  'application' => array(
222
  'label' => 'Application Category',
223
+ 'name' => 'yasr_softwareapplication_category',
224
  'description' => __('Type of software application, e.g. \'Game, Multimedia\'. ', 'yet-another-stars-rating')
225
  ),
226
  'os' => array(
227
  'label' => 'Operating System',
228
+ 'name' => 'yasr_softwareapplication_os',
229
+ 'description' => __('Operating systems supported e.g. (Windows 11, OSX 12, Android 12)' , 'yet-another-stars-rating')
230
  )
231
  );
232
 
233
  $this->echoFields($software_array);
234
 
235
+ $this->offer('yasr_softwareapplication_price',
236
+ 'yasr_softwareapplication_price_currency',
237
+ 'yasr_softwareapplication_price_valid_until',
238
+ 'yasr_softwareapplication_price_availability',
239
+ 'yasr_softwareapplication_price_url');
240
 
241
  ?>
242
 
admin/editor/yasr-metabox-top-right.php CHANGED
@@ -77,7 +77,7 @@ wp_nonce_field('yasr_pro_nonce_fake_ratings_action', 'yasr_pro_nonce_fake_rating
77
  $message_html = '<div title="'.esc_attr__('Copy Shortcode', 'yet-another-stars-rating').'" >';
78
 
79
  $message_html .= sprintf(
80
- __('Remember to insert this shortcode %s where you want to display this rating.',
81
  'yet-another-stars-rating'),
82
  '<code id="yasr-editor-copy-overall" class="yasr-copy-shortcode">[yasr_overall_rating]</code>');
83
 
77
  $message_html = '<div title="'.esc_attr__('Copy Shortcode', 'yet-another-stars-rating').'" >';
78
 
79
  $message_html .= sprintf(
80
+ esc_html__('Remember to insert this shortcode %s where you want to display this rating.',
81
  'yet-another-stars-rating'),
82
  '<code id="yasr-editor-copy-overall" class="yasr-copy-shortcode">[yasr_overall_rating]</code>');
83
 
admin/js/src/yasr-editor-screen.js CHANGED
@@ -41,9 +41,11 @@ function yasrPrintMetaBoxOverall() {
41
  let overallRating = parseFloat(document.getElementById('yasr-overall-rating-value').value);
42
  const copyOverall = document.getElementById('yasr-editor-copy-overall');
43
 
44
- copyOverall.onclick = function (event) {
45
- let el = document.getElementById(event.target.id);
46
- copyToClipboard(el.textContent.trim());
 
 
47
  }
48
 
49
  raterJs({
41
  let overallRating = parseFloat(document.getElementById('yasr-overall-rating-value').value);
42
  const copyOverall = document.getElementById('yasr-editor-copy-overall');
43
 
44
+ if(copyOverall !== null) {
45
+ copyOverall.onclick = function (event) {
46
+ let el = document.getElementById(event.target.id);
47
+ copyToClipboard(el.textContent.trim());
48
+ }
49
  }
50
 
51
  raterJs({
admin/js/yasr-editor-screen.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";const e=e=>{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)};function t(e,t,n=!1,o=.1,a=!0,i=!1,s=!1){let r;r=n||document.getElementById(t),e=parseInt(e),raterJs({starSize:e,showToolTip:!1,element:r,step:o,readOnly:a,rating:i,rateCallback:s})}var n;tippy(document.querySelectorAll(".yasr-copy-shortcode"),{content:"Copied! Insert into your post!",theme:"yasr",arrow:"true",arrowType:"round",trigger:"click"});var o=new Uint8Array(16);function a(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(o)}const i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,s=function(e){return"string"==typeof e&&i.test(e)};for(var r=[],l=0;l<256;++l)r.push((l+256).toString(16).substr(1));const d=function(e,t,n){var o=(e=e||{}).random||(e.rng||a)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=o[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(r[e[t+0]]+r[e[t+1]]+r[e[t+2]]+r[e[t+3]]+"-"+r[e[t+4]]+r[e[t+5]]+"-"+r[e[t+6]]+r[e[t+7]]+"-"+r[e[t+8]]+r[e[t+9]]+"-"+r[e[t+10]]+r[e[t+11]]+r[e[t+12]]+r[e[t+13]]+r[e[t+14]]+r[e[t+15]]).toLowerCase();if(!s(n))throw TypeError("Stringified UUID is invalid");return n}(o)};function y(e){"Product"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"LocalBusiness"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"Recipe"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"SoftwareApplication"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"Book"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"Movie"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none"):document.getElementById("yasr-metabox-info-snippet-container").style.display="none"}function c(e,n,o){const a={action:"yasr_send_id_nameset",set_id:e,post_id:n};return jQuery.post(ajaxurl,a,(function(n){o>1&&(document.getElementById("yasr-loader-select-multi-set").style.display="none");let a=JSON.parse(n),i=document.getElementById("yasr-table-multi-set-admin"),s=document.getElementById("yasr-table-multi-set-admin-visitor");m(a,i),m(a,s,!1),function(e){document.getElementById("yasr-multiset-id").value=e;let n=document.getElementsByClassName("yasr-multiset-admin"),o=[],a=!1;for(let e=0;e<n.length;e++)!function(e){let i=n.item(e).id,s=document.getElementById(i),r=parseInt(s.getAttribute("data-multi-idfield")),l=parseInt(s.getAttribute("data-rating")),d="true"===s.getAttribute("data-readonly"),y={field:r,rating:l};o.push(y),t(32,i,!1,.5,d,!1,(function(e,t){e=e.toFixed(1),e=parseFloat(e),this.setRating(e);for(let t=0;t<o.length;t++)o[t].field===r&&(o[t].rating=e);a=JSON.stringify(o),document.getElementById("yasr-multiset-author-votes").value=a,t()}))}(e)}(e);let r=document.getElementsByClassName("yasr-editor-multiset-id");for(let t=0;t<r.length;t++)r[t].innerText=e})),!1}function m(e,t,n=!0){let o="";for(let t=0;t<e.length;t++){let a=e[t].name,i=0,s="",r=!0;!1!==n&&(i=e[t].average_rating,s='<img src="'+yasrCommonData.loaderHtml+'" alt="yasr-loader"></span>',r=!1);let l=e[t].id;o+="<tr>",o+="<td>"+a+"</td>",o+='<td><div class="yasr-multiset-admin" id="yasr-multiset-admin-'+d()+'" data-rating="'+i+'" data-multi-idfield="'+l+'" data-readonly="'+r+'"></div>',o+="</td>",o+="</tr>"}!1===n&&(o+='<tr><td colspan="2"><input type="submit" class="button button-primary" value="Submit!" disabled></td></tr>'),t.innerHTML=o}document.addEventListener("DOMContentLoaded",(function(t){var n;!0!==document.body.classList.contains("block-editor-page")&&(function(){let t=parseFloat(document.getElementById("yasr-overall-rating-value").value);document.getElementById("yasr-editor-copy-overall").onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},raterJs({starSize:32,step:.1,showToolTip:!1,rating:t,readOnly:!1,element:document.getElementById("yasr-rater-overall"),rateCallback:function(e,t){e=e.toFixed(1),e=parseFloat(e),document.getElementById("yasr-overall-rating-value").value=e,this.setRating(e);document.getElementById("yasr_overall_text").textContent="You've rated "+e,t()}})}(),n={action:"yasr_create_shortcode"},jQuery.get(ajaxurl,n,(function(e){jQuery(e).appendTo("body").hide(),function(){let e=!1;null!==document.getElementById("yasr-editor-multiset-container")&&(e=!0);const t=document.getElementById("yasr-tinypopup-link-doc");jQuery("#yasr-link-tab-main").on("click",(function(){jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-link-tab-main").addClass("nav-tab-active"),jQuery(".yasr-content-tab-tinymce").hide(),jQuery("#yasr-content-tab-main").show(),t.setAttribute("href","https://yetanotherstarsrating.com/yasr-basics-shortcode/?utm_source=wp-plugin&utm_medium=tinymce-popup&utm_campaign=yasr_editor_screen")})),jQuery("#yasr-link-tab-charts").on("click",(function(){jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-link-tab-charts").addClass("nav-tab-active"),jQuery(".yasr-content-tab-tinymce").hide(),jQuery("#yasr-content-tab-charts").show(),t.setAttribute("href","https://yetanotherstarsrating.com/yasr-rankings/?utm_source=wp-plugin&utm_medium=tinymce-popup&utm_campaign=yasr_editor_screen")})),jQuery("#yasr-overall").on("click",(function(){jQuery("#yasr-overall-choose-size").toggle("slow")})),jQuery("#yasr-visitor-votes").on("click",(function(){jQuery("#yasr-visitor-choose-size").toggle("slow")})),jQuery(".yasr-tinymce-shortcode-buttons").on("click",(function(){let e=this.getAttribute("data-shortcode");null==tinyMCE.activeEditor?jQuery("#content").append(e):tinyMCE.activeEditor.execCommand("mceInsertContent",0,e),tb_remove()})),!0===e&&jQuery("#yasr-insert-multiset-select").on("change",(function(){var e=jQuery("input:radio[name=yasr_tinymce_pick_set]:checked").val();let t;t=jQuery("#yasr-allow-vote-multiset").is(":checked")?"[yasr_multiset setid=":"[yasr_visitor_multiset setid=",t+=e,jQuery("#yasr-hide-average-multiset").is(":checked")&&(t+=" show_average='no'"),t+="]",null==tinyMCE.activeEditor?jQuery("#content").append(t):tinyMCE.activeEditor.execCommand("mceInsertContent",0,t),tb_remove()}))}()}))),function(){jQuery("#yasr-metabox-below-editor-structured-data-tab").on("click",(function(e){e.preventDefault(),jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-metabox-below-editor-structured-data-tab").addClass("nav-tab-active"),jQuery(".yasr-metabox-below-editor-content").hide(),jQuery("#yasr-metabox-below-editor-structured-data").show()})),jQuery("#yasr-metabox-below-editor-multiset-tab").on("click",(function(e){e.preventDefault(),jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-metabox-below-editor-multiset-tab").addClass("nav-tab-active"),jQuery(".yasr-metabox-below-editor-content").hide(),jQuery("#yasr-metabox-below-editor-multiset").show()}));let t=document.getElementById("yasr-metabox-below-editor-select-schema").value;null!==document.getElementById("yasr-editor-multiset-container")&&function(){let t=document.getElementById("yasr-editor-multiset-container"),n=parseInt(t.getAttribute("data-nmultiset")),o=parseInt(t.getAttribute("data-setid")),a=parseInt(t.getAttribute("data-postid"));const i=document.getElementById("yasr-editor-copy-readonly-multiset"),s=document.getElementById("yasr-editor-copy-visitor-multiset"),r=document.getElementById("yasr-editor-copy-average-multiset"),l=document.getElementById("yasr-editor-copy-average-vvmultiset"),d=document.getElementById("yasr-pro-comments-enabled-yes"),y=document.getElementById("yasr-pro-multiset-review-switcher");c(o,a,n),i.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},s.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},r.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},l.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},null!==y&&(null!==d&&d.addEventListener("change",(e=>{e.currentTarget.checked||(y.checked=!1)})),y.addEventListener("change",(e=>{e.currentTarget.checked&&(null!==d?d.checked=!0:document.getElementById("yasr-comment-reviews-disabled-switch").checked=!0)}))),n>1&&jQuery("#yasr_select_set").on("change",(function(){return o=jQuery("#yasr_select_set").val(),jQuery("#yasr-loader-select-multi-set").show(),c(o,a,n),!1}))}(),y(t)}()})),document.getElementById("yasr-metabox-below-editor-select-schema").addEventListener("change",(function(){y(this.value)}))})();
1
+ (()=>{"use strict";const e=e=>{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)};function t(e,t,n=!1,o=.1,a=!0,i=!1,s=!1){let r;r=n||document.getElementById(t),e=parseInt(e),raterJs({starSize:e,showToolTip:!1,element:r,step:o,readOnly:a,rating:i,rateCallback:s})}var n;tippy(document.querySelectorAll(".yasr-copy-shortcode"),{content:"Copied! Insert into your post!",theme:"yasr",arrow:"true",arrowType:"round",trigger:"click"});var o=new Uint8Array(16);function a(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(o)}const i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,s=function(e){return"string"==typeof e&&i.test(e)};for(var r=[],l=0;l<256;++l)r.push((l+256).toString(16).substr(1));const d=function(e,t,n){var o=(e=e||{}).random||(e.rng||a)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=o[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(r[e[t+0]]+r[e[t+1]]+r[e[t+2]]+r[e[t+3]]+"-"+r[e[t+4]]+r[e[t+5]]+"-"+r[e[t+6]]+r[e[t+7]]+"-"+r[e[t+8]]+r[e[t+9]]+"-"+r[e[t+10]]+r[e[t+11]]+r[e[t+12]]+r[e[t+13]]+r[e[t+14]]+r[e[t+15]]).toLowerCase();if(!s(n))throw TypeError("Stringified UUID is invalid");return n}(o)};function y(e){"Product"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"LocalBusiness"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"Recipe"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"SoftwareApplication"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"Book"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="none"):"Movie"===e?(document.getElementById("yasr-metabox-info-snippet-container").style.display="",document.getElementById("yasr-metabox-info-snippet-container-movie").style.display="",document.getElementById("yasr-metabox-info-snippet-container-recipe").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-localbusiness").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-product").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-software").style.display="none",document.getElementById("yasr-metabox-info-snippet-container-book").style.display="none"):document.getElementById("yasr-metabox-info-snippet-container").style.display="none"}function c(e,n,o){const a={action:"yasr_send_id_nameset",set_id:e,post_id:n};return jQuery.post(ajaxurl,a,(function(n){o>1&&(document.getElementById("yasr-loader-select-multi-set").style.display="none");let a=JSON.parse(n),i=document.getElementById("yasr-table-multi-set-admin"),s=document.getElementById("yasr-table-multi-set-admin-visitor");m(a,i),m(a,s,!1),function(e){document.getElementById("yasr-multiset-id").value=e;let n=document.getElementsByClassName("yasr-multiset-admin"),o=[],a=!1;for(let e=0;e<n.length;e++)!function(e){let i=n.item(e).id,s=document.getElementById(i),r=parseInt(s.getAttribute("data-multi-idfield")),l=parseInt(s.getAttribute("data-rating")),d="true"===s.getAttribute("data-readonly"),y={field:r,rating:l};o.push(y),t(32,i,!1,.5,d,!1,(function(e,t){e=e.toFixed(1),e=parseFloat(e),this.setRating(e);for(let t=0;t<o.length;t++)o[t].field===r&&(o[t].rating=e);a=JSON.stringify(o),document.getElementById("yasr-multiset-author-votes").value=a,t()}))}(e)}(e);let r=document.getElementsByClassName("yasr-editor-multiset-id");for(let t=0;t<r.length;t++)r[t].innerText=e})),!1}function m(e,t,n=!0){let o="";for(let t=0;t<e.length;t++){let a=e[t].name,i=0,s="",r=!0;!1!==n&&(i=e[t].average_rating,s='<img src="'+yasrCommonData.loaderHtml+'" alt="yasr-loader"></span>',r=!1);let l=e[t].id;o+="<tr>",o+="<td>"+a+"</td>",o+='<td><div class="yasr-multiset-admin" id="yasr-multiset-admin-'+d()+'" data-rating="'+i+'" data-multi-idfield="'+l+'" data-readonly="'+r+'"></div>',o+="</td>",o+="</tr>"}!1===n&&(o+='<tr><td colspan="2"><input type="submit" class="button button-primary" value="Submit!" disabled></td></tr>'),t.innerHTML=o}document.addEventListener("DOMContentLoaded",(function(t){var n;!0!==document.body.classList.contains("block-editor-page")&&(function(){let t=parseFloat(document.getElementById("yasr-overall-rating-value").value);const n=document.getElementById("yasr-editor-copy-overall");null!==n&&(n.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())}),raterJs({starSize:32,step:.1,showToolTip:!1,rating:t,readOnly:!1,element:document.getElementById("yasr-rater-overall"),rateCallback:function(e,t){e=e.toFixed(1),e=parseFloat(e),document.getElementById("yasr-overall-rating-value").value=e,this.setRating(e);document.getElementById("yasr_overall_text").textContent="You've rated "+e,t()}})}(),n={action:"yasr_create_shortcode"},jQuery.get(ajaxurl,n,(function(e){jQuery(e).appendTo("body").hide(),function(){let e=!1;null!==document.getElementById("yasr-editor-multiset-container")&&(e=!0);const t=document.getElementById("yasr-tinypopup-link-doc");jQuery("#yasr-link-tab-main").on("click",(function(){jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-link-tab-main").addClass("nav-tab-active"),jQuery(".yasr-content-tab-tinymce").hide(),jQuery("#yasr-content-tab-main").show(),t.setAttribute("href","https://yetanotherstarsrating.com/yasr-basics-shortcode/?utm_source=wp-plugin&utm_medium=tinymce-popup&utm_campaign=yasr_editor_screen")})),jQuery("#yasr-link-tab-charts").on("click",(function(){jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-link-tab-charts").addClass("nav-tab-active"),jQuery(".yasr-content-tab-tinymce").hide(),jQuery("#yasr-content-tab-charts").show(),t.setAttribute("href","https://yetanotherstarsrating.com/yasr-rankings/?utm_source=wp-plugin&utm_medium=tinymce-popup&utm_campaign=yasr_editor_screen")})),jQuery("#yasr-overall").on("click",(function(){jQuery("#yasr-overall-choose-size").toggle("slow")})),jQuery("#yasr-visitor-votes").on("click",(function(){jQuery("#yasr-visitor-choose-size").toggle("slow")})),jQuery(".yasr-tinymce-shortcode-buttons").on("click",(function(){let e=this.getAttribute("data-shortcode");null==tinyMCE.activeEditor?jQuery("#content").append(e):tinyMCE.activeEditor.execCommand("mceInsertContent",0,e),tb_remove()})),!0===e&&jQuery("#yasr-insert-multiset-select").on("change",(function(){var e=jQuery("input:radio[name=yasr_tinymce_pick_set]:checked").val();let t;t=jQuery("#yasr-allow-vote-multiset").is(":checked")?"[yasr_multiset setid=":"[yasr_visitor_multiset setid=",t+=e,jQuery("#yasr-hide-average-multiset").is(":checked")&&(t+=" show_average='no'"),t+="]",null==tinyMCE.activeEditor?jQuery("#content").append(t):tinyMCE.activeEditor.execCommand("mceInsertContent",0,t),tb_remove()}))}()}))),function(){jQuery("#yasr-metabox-below-editor-structured-data-tab").on("click",(function(e){e.preventDefault(),jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-metabox-below-editor-structured-data-tab").addClass("nav-tab-active"),jQuery(".yasr-metabox-below-editor-content").hide(),jQuery("#yasr-metabox-below-editor-structured-data").show()})),jQuery("#yasr-metabox-below-editor-multiset-tab").on("click",(function(e){e.preventDefault(),jQuery(".yasr-nav-tab").removeClass("nav-tab-active"),jQuery("#yasr-metabox-below-editor-multiset-tab").addClass("nav-tab-active"),jQuery(".yasr-metabox-below-editor-content").hide(),jQuery("#yasr-metabox-below-editor-multiset").show()}));let t=document.getElementById("yasr-metabox-below-editor-select-schema").value;null!==document.getElementById("yasr-editor-multiset-container")&&function(){let t=document.getElementById("yasr-editor-multiset-container"),n=parseInt(t.getAttribute("data-nmultiset")),o=parseInt(t.getAttribute("data-setid")),a=parseInt(t.getAttribute("data-postid"));const i=document.getElementById("yasr-editor-copy-readonly-multiset"),s=document.getElementById("yasr-editor-copy-visitor-multiset"),r=document.getElementById("yasr-editor-copy-average-multiset"),l=document.getElementById("yasr-editor-copy-average-vvmultiset"),d=document.getElementById("yasr-pro-comments-enabled-yes"),y=document.getElementById("yasr-pro-multiset-review-switcher");c(o,a,n),i.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},s.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},r.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},l.onclick=function(t){let n=document.getElementById(t.target.id);e(n.textContent.trim())},null!==y&&(null!==d&&d.addEventListener("change",(e=>{e.currentTarget.checked||(y.checked=!1)})),y.addEventListener("change",(e=>{e.currentTarget.checked&&(null!==d?d.checked=!0:document.getElementById("yasr-comment-reviews-disabled-switch").checked=!0)}))),n>1&&jQuery("#yasr_select_set").on("change",(function(){return o=jQuery("#yasr_select_set").val(),jQuery("#yasr-loader-select-multi-set").show(),c(o,a,n),!1}))}(),y(t)}()})),document.getElementById("yasr-metabox-below-editor-select-schema").addEventListener("change",(function(){y(this.value)}))})();
includes/classes/YasrMultiSetData.php CHANGED
@@ -126,17 +126,19 @@ class YasrMultiSetData {
126
  /**
127
  * Get from the db all the values for VisitorMultiSet
128
  *
129
- * @param $post_id
130
- * @param $set_id
131
  * @param bool $visitor_multiset
 
132
  *
133
  * @return array|bool
134
  */
135
- public static function returnMultisetContent($post_id, $set_id, $visitor_multiset=false) {
136
- $set_id = (int)$set_id;
137
- $post_id = (int)$post_id;
 
138
 
139
- if ($post_id === 0) {
140
  return false;
141
  }
142
 
@@ -147,8 +149,8 @@ class YasrMultiSetData {
147
  return false;
148
  }
149
 
150
- if($visitor_multiset === true) {
151
- return self::returnArrayFieldsRatingsVisitor($set_id, $set_fields, $post_id);
152
  }
153
 
154
  //return
@@ -236,28 +238,31 @@ class YasrMultiSetData {
236
  * 'value_rating' => 3,
237
  * )
238
  *
239
- * @param integer $set_id the set id
240
  * @param array $set_fields an array with fields names and id
241
- * @param integer|bool $post_id the post_id
242
- * @param integer $comment_id the comment_id
243
  *
244
  * @return bool | array
245
  */
246
 
247
- public static function returnArrayFieldsRatingsVisitor($set_id, $set_fields, $post_id=false, $comment_id=0) {
248
  $array_to_return = array();
249
 
250
  global $wpdb;
251
 
252
  $set_id = (int)$set_id;
253
  $comment_id = (int)$comment_id;
 
254
 
255
  if (!$set_fields) {
256
  return false;
257
  }
258
 
259
- if(!is_int($post_id)) {
260
- $post_id = get_the_ID();
 
 
261
  }
262
 
263
  //get meta values (field id and rating)
@@ -266,11 +271,11 @@ class YasrMultiSetData {
266
  COUNT(l.vote) AS number_of_votes,
267
  field_id AS field
268
  FROM " . YASR_LOG_MULTI_SET . " AS l
269
- WHERE l.post_id=%d
270
- AND l.set_type=%d
271
- AND l.comment_id=%d
272
  GROUP BY l.field_id
273
- ORDER BY l.field_id", $post_id, $set_id, $comment_id), ARRAY_A);
274
 
275
  //index
276
  $i = 0;
126
  /**
127
  * Get from the db all the values for VisitorMultiSet
128
  *
129
+ * @param $post_id
130
+ * @param $set_id
131
  * @param bool $visitor_multiset
132
+ * @param int $comment_id
133
  *
134
  * @return array|bool
135
  */
136
+ public static function returnMultisetContent($post_id, $set_id, $visitor_multiset=false, $comment_id=0) {
137
+ $set_id = (int)$set_id;
138
+ $post_id = (int)$post_id;
139
+ $comment_id = (int)$comment_id;
140
 
141
+ if ($post_id === 0 && $comment_id === 0) {
142
  return false;
143
  }
144
 
149
  return false;
150
  }
151
 
152
+ if($visitor_multiset === true || $comment_id > 0) {
153
+ return self::returnArrayFieldsRatingsVisitor($set_id, $set_fields, $comment_id, $post_id);
154
  }
155
 
156
  //return
238
  * 'value_rating' => 3,
239
  * )
240
  *
241
+ * @param int $set_id the set id
242
  * @param array $set_fields an array with fields names and id
243
+ * @param int $comment_id the comment_id
244
+ * @param int $post_id the post_id
245
  *
246
  * @return bool | array
247
  */
248
 
249
+ public static function returnArrayFieldsRatingsVisitor($set_id, $set_fields, $comment_id, $post_id) {
250
  $array_to_return = array();
251
 
252
  global $wpdb;
253
 
254
  $set_id = (int)$set_id;
255
  $comment_id = (int)$comment_id;
256
+ $post_id = (int)$post_id;
257
 
258
  if (!$set_fields) {
259
  return false;
260
  }
261
 
262
+ if($post_id < 1) {
263
+ $and_post_id = '';
264
+ } else {
265
+ $and_post_id = 'AND l.post_id='.$post_id;
266
  }
267
 
268
  //get meta values (field id and rating)
271
  COUNT(l.vote) AS number_of_votes,
272
  field_id AS field
273
  FROM " . YASR_LOG_MULTI_SET . " AS l
274
+ WHERE l.set_type=%d
275
+ AND l.comment_id=%d ".
276
+ esc_sql($and_post_id)."
277
  GROUP BY l.field_id
278
+ ORDER BY l.field_id",$set_id, $comment_id), ARRAY_A);
279
 
280
  //index
281
  $i = 0;
includes/rest/classes/YasrCustomEndpoint.php CHANGED
@@ -40,8 +40,7 @@ class YasrCustomEndpoint extends WP_REST_Controller {
40
  /*
41
  * Param for this route must be
42
  * YOURSITE/wp-json/yet-another-stars-rating/v1/yasr-multiset/?set_id&post_id=<ID>
43
- * OPTIONAL &visitor=1
44
- *
45
  */
46
 
47
  $base = 'yasr-multiset';
@@ -55,7 +54,7 @@ class YasrCustomEndpoint extends WP_REST_Controller {
55
  'sanitize_callback' => array($this, 'sanitizeInput')
56
  ),
57
  'post_id' => array(
58
- 'required' => true,
59
  'sanitize_callback' => array($this, 'sanitizeInput')
60
  ),
61
  'visitor' => array(
@@ -63,6 +62,10 @@ class YasrCustomEndpoint extends WP_REST_Controller {
63
  'required' => false,
64
  'sanitize_callback' => array($this, 'sanitizeInput')
65
  ),
 
 
 
 
66
  ),
67
  'permission_callback' => static function () {
68
  return true;
@@ -84,46 +87,30 @@ class YasrCustomEndpoint extends WP_REST_Controller {
84
  * @param WP_REST_Request $request
85
  *
86
  * @return WP_Error|WP_REST_Response
 
87
  */
88
  public function multiSet ($request) {
89
  /*
90
  * Get cleaned params
91
  */
92
- $set_id = $request['set_id'];
93
- $post_id = $request['post_id'];
94
- $visitor = $request['visitor'];
95
-
96
- $data_to_return = array(
97
- 'set_id' => $set_id
98
- );
99
-
100
- $invalid_set = false;
101
 
102
  //if $visitor === 1 then get data from yasr_visitor_multiset
103
  if($visitor === 1) {
104
- $data_to_return['yasr_visitor_multiset'] = YasrMultiSetData::returnMultisetContent($post_id, $set_id, true);
105
- if ($data_to_return['yasr_visitor_multiset'] === false) {
106
- $invalid_set = true;
107
- }
108
- } else {
109
- $data_to_return['yasr_multiset'] = YasrMultiSetData::returnMultisetContent($post_id, $set_id);
110
- if ($data_to_return['yasr_multiset'] === false) {
111
- $invalid_set = true;
112
- }
113
  }
114
 
115
- if ($invalid_set === true) {
116
- return new WP_Error(
117
- 'invalid_multiset',
118
- __('This Multi Set doesn\'t exists', 'yet-another-stars-rating'),
119
- 400
120
- );
121
  }
122
 
123
- $response = new WP_REST_Response($data_to_return);
124
- $response->set_status(200);
125
 
126
- return $response;
127
  }
128
 
129
  /**
@@ -183,9 +170,7 @@ class YasrCustomEndpoint extends WP_REST_Controller {
183
  * @return WP_Error|WP_REST_Response
184
  */
185
  public function ranking($request){
186
- /*
187
- * Get cleaned params
188
- */
189
  $source = $request['source'];
190
 
191
  $data_to_return = YasrShortcodesAjax::rankingData($source, $request);
@@ -219,10 +204,9 @@ class YasrCustomEndpoint extends WP_REST_Controller {
219
  if($key === 'post_id') {
220
  $post_id = (int)$param;
221
 
222
- /*if post_id is null means that is not set in the request.
223
- * (int) will convert it to 0.
224
- * When WordPress is installed, the first post has ID = 1
225
- */
226
  if ($post_id === 0) {
227
  return new WP_Error (
228
  'wrong_post_id',
@@ -250,6 +234,30 @@ class YasrCustomEndpoint extends WP_REST_Controller {
250
  return (int)$param;
251
  }
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  if($key === 'source') {
254
  if( $param === 'overall_rating'
255
  || $param === 'visitor_votes'
@@ -271,4 +279,113 @@ class YasrCustomEndpoint extends WP_REST_Controller {
271
  return $param;
272
 
273
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
40
  /*
41
  * Param for this route must be
42
  * YOURSITE/wp-json/yet-another-stars-rating/v1/yasr-multiset/?set_id&post_id=<ID>
43
+ * OPTIONAL &visitor=1 OPTIONAL comment_id
 
44
  */
45
 
46
  $base = 'yasr-multiset';
54
  'sanitize_callback' => array($this, 'sanitizeInput')
55
  ),
56
  'post_id' => array(
57
+ 'required' => false,
58
  'sanitize_callback' => array($this, 'sanitizeInput')
59
  ),
60
  'visitor' => array(
62
  'required' => false,
63
  'sanitize_callback' => array($this, 'sanitizeInput')
64
  ),
65
+ 'comment_id' => array (
66
+ 'required' => false,
67
+ 'sanitize_callback' => array($this, 'sanitizeInput')
68
+ )
69
  ),
70
  'permission_callback' => static function () {
71
  return true;
87
  * @param WP_REST_Request $request
88
  *
89
  * @return WP_Error|WP_REST_Response
90
+ *
91
  */
92
  public function multiSet ($request) {
93
  /*
94
  * Get cleaned params
95
  */
96
+ $set_id = $request['set_id']; //this is mandatory, so it is sanitized and is always an int
97
+ $post_id = $request['post_id']; //not mandatory, can be null
98
+ $visitor = $request['visitor']; //not mandatory, can be null
99
+ $comment_id = $request['comment_id']; //not mandatory, can be null
 
 
 
 
 
100
 
101
  //if $visitor === 1 then get data from yasr_visitor_multiset
102
  if($visitor === 1) {
103
+ return $this->returnVisitorMultiset($post_id, $set_id);
 
 
 
 
 
 
 
 
104
  }
105
 
106
+ //comment_id is an int here, if is > than 0 is valid
107
+ if($comment_id !== null && $comment_id > 0) {
108
+ return $this->returnCommentMultiset($set_id, $comment_id);
 
 
 
109
  }
110
 
111
+ //last one return author multiset
112
+ return $this->returnAuthorMultiset($post_id, $set_id);
113
 
 
114
  }
115
 
116
  /**
170
  * @return WP_Error|WP_REST_Response
171
  */
172
  public function ranking($request){
173
+ //Get cleaned params
 
 
174
  $source = $request['source'];
175
 
176
  $data_to_return = YasrShortcodesAjax::rankingData($source, $request);
204
  if($key === 'post_id') {
205
  $post_id = (int)$param;
206
 
207
+ //if post_id is null means that is not set in the request.
208
+ //(int) will convert it to 0.
209
+ //When WordPress is installed, the first post has ID = 1
 
210
  if ($post_id === 0) {
211
  return new WP_Error (
212
  'wrong_post_id',
234
  return (int)$param;
235
  }
236
 
237
+ if($key === 'comment_id') {
238
+ $comment_id = (int)$param;
239
+
240
+ //When WordPress is installed, the first comment has ID = 1
241
+ if ($comment_id === 0) {
242
+ return new WP_Error (
243
+ 'wrong_comment_id',
244
+ esc_html__('Invalid Comment ID', 'yet-another-stars-rating'),
245
+ 400
246
+ );
247
+ }
248
+
249
+ //Check if exists a post with this ID
250
+ if (get_comment($comment_id) === null) {
251
+ return new WP_Error (
252
+ 'wrong_comment_id',
253
+ 'This comment doesn\'t exists',
254
+ 404
255
+ );
256
+ }
257
+
258
+ return $comment_id;
259
+ }
260
+
261
  if($key === 'source') {
262
  if( $param === 'overall_rating'
263
  || $param === 'visitor_votes'
279
  return $param;
280
 
281
  }
282
+
283
+ /**
284
+ * @author Dario Curvino <@dudo>
285
+ * @since
286
+ * @param $post_id
287
+ * @param $set_id
288
+ *
289
+ * @return bool|\WP_Error|\WP_REST_Response
290
+ */
291
+ protected function returnVisitorMultiset($post_id, $set_id) {
292
+ if(!$post_id) {
293
+ return $this->returnErrorPostId();
294
+ }
295
+
296
+ $data_to_return['yasr_visitor_multiset'] = YasrMultiSetData::returnMultisetContent($post_id, $set_id, true);
297
+ if ($data_to_return['yasr_visitor_multiset'] === false) {
298
+ return $this->returnInvalidMultiset();
299
+ }
300
+
301
+ return $this->returnMultisetResponse($data_to_return, $set_id);
302
+ }
303
+
304
+
305
+ /**
306
+ * @author Dario Curvino <@dudo>
307
+ * @since 2.9.8
308
+ * @param $set_id
309
+ * @param $comment_id
310
+ *
311
+ * @return \WP_Error|\WP_REST_Response
312
+ */
313
+ protected function returnCommentMultiset($set_id, $comment_id) {
314
+ //if comment id is valid, post_id can be ignored at all
315
+ $data_to_return['yasr_comment_multiset'] = YasrMultiSetData::returnMultisetContent(false, $set_id, false, $comment_id);
316
+ if ($data_to_return['yasr_comment_multiset'] === false) {
317
+ return $this->returnInvalidMultiset();
318
+ }
319
+
320
+ return $this->returnMultisetResponse($data_to_return, $set_id);
321
+ }
322
+
323
+ /**
324
+ * @author Dario Curvino <@dudo>
325
+ * @since 2.9.8
326
+ * @param $post_id
327
+ * @param $set_id
328
+ *
329
+ * @return bool|\WP_Error|\WP_REST_Response
330
+ */
331
+ protected function returnAuthorMultiset($post_id, $set_id) {
332
+ if(!$post_id) {
333
+ return $this->returnErrorPostId();
334
+ }
335
+
336
+ $data_to_return['yasr_multiset'] = YasrMultiSetData::returnMultisetContent($post_id, $set_id);
337
+ if ($data_to_return['yasr_multiset'] === false) {
338
+ return $this->returnInvalidMultiset();
339
+ }
340
+
341
+ return $this->returnMultisetResponse($data_to_return, $set_id);
342
+ }
343
+
344
+ /**
345
+ * @author Dario Curvino <@dudo>
346
+ * @since 2.9.8
347
+ */
348
+ protected function returnInvalidMultiset() {
349
+ return new WP_Error(
350
+ 'invalid_multiset',
351
+ __('This Multi Set doesn\'t exists', 'yet-another-stars-rating'),
352
+ 400
353
+ );
354
+ }
355
+
356
+ /**
357
+ * This function is called when post_is is mandatory
358
+ *
359
+ * @author Dario Curvino <@dudo>
360
+ * @since 2.9.8
361
+ *
362
+ * @return bool|\WP_Error
363
+ */
364
+ protected function returnErrorPostId() {
365
+ return new WP_Error(
366
+ 'missing_post_id',
367
+ 'You must specific post id here',
368
+ 400
369
+ );
370
+ }
371
+
372
+ /**
373
+ * @author Dario Curvino <@dudo>
374
+ * @since 2.9.8
375
+ *
376
+ * @param $data_to_return
377
+ * @param $set_id
378
+ *
379
+ * @return \WP_REST_Response
380
+ */
381
+ protected function returnMultisetResponse($data_to_return, $set_id) {
382
+ $data = array(
383
+ 'set_id' => $set_id
384
+ );
385
+
386
+ $response = new WP_REST_Response(array_merge($data, $data_to_return));
387
+ $response->set_status(200);
388
+
389
+ return $response;
390
+ }
391
  }
includes/yasr-includes-functions.php CHANGED
@@ -27,7 +27,7 @@ add_action('wp_enqueue_scripts', 'yasr_add_scripts_includes', 11);
27
  add_action('admin_enqueue_scripts', 'yasr_add_scripts_includes', 11);
28
 
29
  function yasr_add_scripts_includes() {
30
- //This is required to use wp_add_inline_script without dependency
31
  //https://wordpress.stackexchange.com/a/311279/48442
32
  wp_register_script( 'yasr-global-data', '', [], '', true );
33
  wp_enqueue_script( 'yasr-global-data' );
@@ -35,18 +35,23 @@ function yasr_add_scripts_includes() {
35
  $yasr_visitor_votes_loader = '<div id="loader-visitor-rating" style="display: inline-block">&nbsp; '.
36
  ' <img src="' . esc_url(YASR_IMG_DIR . 'loader.gif').'" title="yasr-loader" alt="yasr-loader"></div>';
37
 
38
- $yasr_common_data = json_encode(array(
39
  'siteUrl' => site_url(),
40
  'ajaxurl' => admin_url('admin-ajax.php'),
41
  'visitorStatsEnabled' => YASR_VISITORS_STATS,
42
  'ajaxEnabled' => YASR_ENABLE_AJAX,
43
  'loaderHtml' => $yasr_visitor_votes_loader,
44
- ));
45
 
46
- //check if wp_add_inline_script has already run before
 
 
 
47
  if(!defined('YASR_GLOBAL_DATA_EXISTS')) {
48
- wp_add_inline_script(
49
- 'yasr-global-data', 'var yasrCommonData = ' . $yasr_common_data, 'before'
 
 
50
  );
51
 
52
  //use a constant to be sure that yasr-global-data is not loaded twice
27
  add_action('admin_enqueue_scripts', 'yasr_add_scripts_includes', 11);
28
 
29
  function yasr_add_scripts_includes() {
30
+ //This is required to use wp_localize_script without dependency
31
  //https://wordpress.stackexchange.com/a/311279/48442
32
  wp_register_script( 'yasr-global-data', '', [], '', true );
33
  wp_enqueue_script( 'yasr-global-data' );
35
  $yasr_visitor_votes_loader = '<div id="loader-visitor-rating" style="display: inline-block">&nbsp; '.
36
  ' <img src="' . esc_url(YASR_IMG_DIR . 'loader.gif').'" title="yasr-loader" alt="yasr-loader"></div>';
37
 
38
+ $yasr_common_data = array(
39
  'siteUrl' => site_url(),
40
  'ajaxurl' => admin_url('admin-ajax.php'),
41
  'visitorStatsEnabled' => YASR_VISITORS_STATS,
42
  'ajaxEnabled' => YASR_ENABLE_AJAX,
43
  'loaderHtml' => $yasr_visitor_votes_loader,
44
+ );
45
 
46
+ //check if wp_localize_script has already run before
47
+ //since version 2.9.8 wp_localize_script is used again instead of wp_add_inline_script.
48
+ //For some reasons, wp_add_inline_script simply didn't run in some cases
49
+ // (e.g. https://wordpress.org/support/topic/yellow-star-not-appear/)
50
  if(!defined('YASR_GLOBAL_DATA_EXISTS')) {
51
+ wp_localize_script(
52
+ 'yasr-global-data',
53
+ 'yasrCommonData',
54
+ $yasr_common_data
55
  );
56
 
57
  //use a constant to be sure that yasr-global-data is not loaded twice
includes/yasr-includes-init.php CHANGED
@@ -250,6 +250,9 @@ $supported_schema_types = json_encode(
250
  'SoftwareApplication'
251
  )
252
  );
 
 
 
253
  $array_item_type_info = json_encode(
254
  array(
255
  'yasr_schema_title',
@@ -284,13 +287,13 @@ $array_item_type_info = json_encode(
284
  'yasr_recipe_recipeingredient',
285
  'yasr_recipe_recipeinstructions',
286
  'yasr_recipe_video',
287
- 'yasr_software_application',
288
- 'yasr_software_os',
289
- 'yasr_software_price',
290
- 'yasr_software_price_availability',
291
- 'yasr_software_price_currency',
292
- 'yasr_software_price_url',
293
- 'yasr_software_price_valid_until',
294
  )
295
  );
296
 
250
  'SoftwareApplication'
251
  )
252
  );
253
+
254
+ //here the array member must contain main itemtype name
255
+ //e.g. yasr_softwareapplication contain 'SoftwareApplication'
256
  $array_item_type_info = json_encode(
257
  array(
258
  'yasr_schema_title',
287
  'yasr_recipe_recipeingredient',
288
  'yasr_recipe_recipeinstructions',
289
  'yasr_recipe_video',
290
+ 'yasr_softwareapplication_category',
291
+ 'yasr_softwareapplication_os',
292
+ 'yasr_softwareapplication_price',
293
+ 'yasr_softwareapplication_price_availability',
294
+ 'yasr_softwareapplication_price_currency',
295
+ 'yasr_softwareapplication_price_url',
296
+ 'yasr_softwareapplication_price_valid_until',
297
  )
298
  );
299
 
public/classes/YasrRichSnippets.php CHANGED
@@ -487,17 +487,17 @@ class YasrRichSnippets {
487
  * @return array
488
  */
489
  private function softwareApplication($post_meta) {
490
- $rich_snippet['applicationCategory'] = $post_meta['yasr_software_application'];
491
- $rich_snippet['operatingSystem'] = $post_meta['yasr_software_os'];
492
 
493
- if(!empty($post_meta['yasr_software_price'])) {
494
  $rich_snippet['offers'] = array(
495
  '@type' => 'Offer',
496
- 'price' => $post_meta['yasr_software_price'],
497
- 'priceCurrency' => $post_meta['yasr_software_price_currency'],
498
- 'priceValidUntil' => $post_meta['yasr_software_price_valid_until'],
499
- 'availability' => $post_meta['yasr_software_price_availability'],
500
- 'url' => $post_meta['yasr_software_price_url'],
501
  );
502
 
503
  }
487
  * @return array
488
  */
489
  private function softwareApplication($post_meta) {
490
+ $rich_snippet['applicationCategory'] = $post_meta['yasr_softwareapplication_category'];
491
+ $rich_snippet['operatingSystem'] = $post_meta['yasr_softwareapplication_os'];
492
 
493
+ if(!empty($post_meta['yasr_softwareapplication_price'])) {
494
  $rich_snippet['offers'] = array(
495
  '@type' => 'Offer',
496
+ 'price' => $post_meta['yasr_softwareapplication_price'],
497
+ 'priceCurrency' => $post_meta['yasr_softwareapplication_price_currency'],
498
+ 'priceValidUntil' => $post_meta['yasr_softwareapplication_price_valid_until'],
499
+ 'availability' => $post_meta['yasr_softwareapplication_price_availability'],
500
+ 'url' => $post_meta['yasr_softwareapplication_price_url'],
501
  );
502
 
503
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: rating, rate post, rate page, star rating, google rating, votes
4
  Requires at least: 5.0
5
  Contributors: Dudo
6
  Tested up to: 5.9
7
- Stable tag: 2.9.7
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
@@ -197,6 +197,12 @@ Yes, YASR is 100% fully compatible with PHP 8
197
 
198
  The full changelog can be found in the plugin's directory. Recent entries:
199
 
 
 
 
 
 
 
200
  = 2.9.7 =
201
  * NEW FEATURE: auto insert option has now a new feature: it is possible to place shortcodes on both above and below the content
202
  * TWEAKED: attribute 'custom-fields' is added for all CPTS, to avoid compatibility issue in Gutenberg
4
  Requires at least: 5.0
5
  Contributors: Dudo
6
  Tested up to: 5.9
7
+ Stable tag: 2.9.8
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
10
  Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
197
 
198
  The full changelog can be found in the plugin's directory. Recent entries:
199
 
200
+ = 2.9.8 =
201
+ * TWEAKED: updated rest api
202
+ * FIX: softwareApplication itemType didn't get saved
203
+ * Fix: impossible to rate for overall rating in certain circumstances.
204
+ * Fix: minor css fixes in admin area
205
+
206
  = 2.9.7 =
207
  * NEW FEATURE: auto insert option has now a new feature: it is possible to place shortcodes on both above and below the content
208
  * TWEAKED: attribute 'custom-fields' is added for all CPTS, to avoid compatibility issue in Gutenberg
yet-another-stars-rating.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
7
- * Version: 2.9.7
8
  * Requires at least: 5.6
9
  * Requires PHP: 5.4
10
  * Author: Dario Curvino
@@ -78,7 +78,7 @@ if ( !function_exists( 'yasr_fs' ) ) {
78
  yasr_fs();
79
  // Signal that SDK was initiated.
80
  do_action( 'yasr_fs_loaded' );
81
- define( 'YASR_VERSION_NUM', '2.9.7' );
82
  //Plugin absolute path
83
  //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
84
  define( 'YASR_ABSOLUTE_PATH', __DIR__ );
4
  * Plugin Name: Yet Another Stars Rating
5
  * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/
6
  * Description: Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO
7
+ * Version: 2.9.8
8
  * Requires at least: 5.6
9
  * Requires PHP: 5.4
10
  * Author: Dario Curvino
78
  yasr_fs();
79
  // Signal that SDK was initiated.
80
  do_action( 'yasr_fs_loaded' );
81
+ define( 'YASR_VERSION_NUM', '2.9.8' );
82
  //Plugin absolute path
83
  //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
84
  define( 'YASR_ABSOLUTE_PATH', __DIR__ );