Support » Plugin: Rate my Post - WP Rating System » Issue with {{avgrating}} display

  • Resolved nswm

    (@nswm)


    Hi Blaz

    First;y, great work on this plugin. I have everything setup and working well except one thing. I’m using the shortcode to display the rating on my posts. When I include the {{avgrating}} variable (and if I leave the default), it seems to show “1 2 3 4 5” (plus a couple of line breaks) rather than the average rating.

    You can see an example on my page: https://nswm.co.uk/insights/northstar-blog/do-you-suffer-from-money-tunnel-vision

    Are you able to help or suggest anything I could try?

    Thanks in advance

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Blaz K.

    (@blazk)

    Hi @nswm,

    I don’t completely understand what you mean by: “When I include the {{avgrating}} variable (and if I leave the default)”. You are inserting the shortcode like this [ratemypost] in your posts right?

    Blaz

    Hi. Yes, sorry I wasn’t clear. I’m using the shortcode [ratemypost].

    In settings, if I leave “Custom results text” blank to use the default text, it displays:

    “Average rating
    1 2 3 4 5

    / 5. Ratings: 32”

    (note line breaks and odd “1 2 3 4 5” text)

    It also displays this odd text if I use the {{avgrating}} variable in the “Custom results text” field.

    Hope that explains the issue a little clearer.

    Plugin Author Blaz K.

    (@blazk)

    @nswm, it explains better but to be honest I have no idea where that is coming from. It certainly doesn’t from the plugin. I recommend disabling other plugins and seeing if there is an incompatible plugin on your website.

    Blaz

    Hi again, Blaz.

    Thanks for the quick responses. I tried disabling all plugins and removing all my custom CSS but the issue persists.

    What is interesting is that when I enable ‘Add rating widget to all posts’, the ratings display correctly at the bottom of the page so it appears to be an issue with the shortcode only.

    I’m no coder but I inspected the elements of both insertion methods to see if there were differences.

    At the point in the code I think the {{avgrating}} variable is brought through, in the shortcode version code, it adds the lines:

    <p class=”stars”>
    <span>
    1
    2
    3
    4
    5
    <span>
    </p>

    These lines don’t appear to be present when inserted using the ‘Add rating widget to all posts’ method. The code then continues the same in both insertion methods.

    Any ideas? Thanks again.

    That code again

    <p class="stars">
    <span>
    <a class="star-1" href="#">1</a>
    <a class="star-2" href="#">2</a>
    <a class="star-3" href="#">3</a>
    <a class="star-4" href="#">4</a>
    <a class="star-5" href="#">5</a>
    <span>
    </p>
    Plugin Author Blaz K.

    (@blazk)

    Hi @nswm,

    I got very curious about this issue so I took a bit more time to investigate it 🙂 I first scanned the plugin’s code and as I assumed there is no such syntax in the Rate my Post plugin. That is being appended to <p id=”voting-results” style=”font-size:10px; “> by javascript. If you disable JS you will see that the code above is not present. Then I did a check what is pushing that to the paragraph and here is the culprit: https://nswm.co.uk/min/cc2fb.js (search for <p class=”stars”>). Since you are minifying and combining resources it’s hard to say whether it’s the theme or a plugin but you should be able to identify the problem if you temporarily disable minify/combine.
    Hope this was helpful 🙂

    Blaz

    Hi Blaz

    Thanks again for looking into this. I appreciate the help and understand the limits of what you can provide, of course. As background, I use the Divi theme which is pretty popular. What I think I have found is some sort of conflict with the Javascript in the theme – specifically for the WooCommerce module (which I don’t use). I think this uses a rating system (for product reviews?)

    I’m already in way over my head and don’t really understand much of this, but I used a string locator and tracked down this line in the theme JS and removed it:

    window.et_pb_init_woo_star_rating=function($rating_selector){var $existing_stars=$rating_selector.closest("div").find("p.stars");0<$existing_stars.length&&$existing_stars.remove(),$rating_selector.hide().before('<p class="stars">\t\t\t\t<span>\t\t\t\t\t<a class="star-1" href="#">1</a>\t\t\t\t\t<a class="star-2" href="#">2</a>\t\t\t\t\t<a class="star-3" href="#">3</a>\t\t\t\t\t<a class="star-4" href="#">4</a>\t\t\t\t\t<a class="star-5" href="#">5</a>\t\t\t\t</span>\t\t\t</p>')}

    Following the removal of this, the ratings shortcode seemed to work. My best guess is that there is some sort of variable (using a variant of ‘stars’?) that is shared between this and your plugin or something.

    Do you think this sounds feasible and broadly right? If, so, I’ll contact the theme to try to figure out how I can remove this code from each theme updated.

    I may be way off track here but need to get this nailed down before I add the ratings shortcode to all my posts.

    I think your rating plugin is the best out there so really determined to get this working with my theme.

    Thanks again.

    Plugin Author Blaz K.

    (@blazk)

    Hi @nswm,

    thank you for sharing this with me. I know that the Divi theme is fairly popular and thus I would really like to make the plugin compatible with it. But it’s a bit hard because it’s a premium theme 🙂 Is there any chance you could add the above listed JS back and then try changing rate-my-post\public\partials\rmp-star-rating-widget.php on line 88 from:

    
    <p id="voting-results" style="<?php echo $custom_font_sizes['textFontSize']; ?> <?php echo ( !$ajaxLoad && !$avgRating ) ? 'display: none;' : ''; ?>">
    

    to

    
    <p id="rmp-voting-results" style="<?php echo $custom_font_sizes['textFontSize']; ?> <?php echo ( !$ajaxLoad && !$avgRating ) ? 'display: none;' : ''; ?>">
    

    Just to see if the code still gets printed there (the plugin will not work properly afterwards). If it doesn’t get printed I could modify the plugin accordingly and push out an update.

    Alternatively, you could also ask the Divi team if it’s possible to dequeue the script that is interfering.

    Let me know what you figure out.

    Blaz

    Hi Blaz

    I’ve changed that code and it’s live on https://nswm.co.uk/insights/northstar-blog/do-you-suffer-from-money-tunnel-vision. The new id ‘rmp-voting-results’ shows but so too does the odd ‘1 2 3 4 5’ text still show.

    Plugin Author Blaz K.

    (@blazk)

    Oh damn, I hoped that there is some kind of id conflict and this will solve the problem 🙂 Is there any chance you could share the complete js file where that code lives, preferably in a non minified version?

    Did you hear back from Divi?

    Blaz

    Hi Blaz

    I’ve not contacted Elegant Themes (Divi) yet but will do so. Can I email you as it may be easier if sending large files. I could attach the .js file in question maybe.

    I have turned off all minify options in relation to JS I can see and purged the minified JS I think. The only reference to this text is now in the file wp-content/themes/Divi/js/custom.min.js. I guess this is a minified file given the ‘min’. Would the contents of this file be what you need or can I do something else somehow?

    Plugin Author Blaz K.

    (@blazk)

    I think it’ll be okay 🙂 you can contact me via my website: https://blazzdev.com/

    BTW, I also contacted DIVI to see if they are so nice to share a copy of theme for development environment with me 🙂

    Blaz

    Great. Thanks. I’ve sent the whole .js file via your website.

    Plugin Author Blaz K.

    (@blazk)

    Fixed in version 2.10.2 which has been just released 🙂

    Super, Blaz.

    I’ve updated and can confirm this has resolved the issue.

    Thanks again for your help.

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.