• Resolved hernan2022

    (@hernan2022)


    Hello, I have a cache problem in Extra Theme (it is a theme from Elegant Themes, the same developers of DIVI). My programming level is quite basic. The project is not “live” yet, so I can test freely

    This theme has an integrated rating system, visitors can give 1 or 5 stars to each post. I would very much like to maintain the rating system, the theme shows this information in various sections of the website and it would also help me a lot to evaluate if the entries really help or add value

    When I installed LiteSpeed I noticed that many times visitors see the rating marked without having voted. For example, some devices enter in a post and immediately see this, without being able to vote themselves:

    I have carried out the tests on many devices without sharing Wi-Fi (to ensure that the IPs are completely different). The weird thing is that sometimes it works as expected (even adding up the total vote and calculating an average) But eventually it gets stuck until the next cache purge

    I have contacted Elegant Themes, they can’t really explain why, they simply apologize and offer me another caching plugin. But I can comment that the file for this functionality, located in extra/includes/ratings.php, looks something like this:

    https://www.dropbox.com/scl/fi/plv0q9uxm6a43uk9fll62/ratings.php?rlkey=uk5xhsgpso90431djs50ey8ot&dl=0

    Apparently the operation of the rating system is very similar to that of the comments. With this code snippet I can see the ratings in the WordPress backend as regular comments:

    add_action('init', 'ebc_show_ratings_comments');
    
    function ebc_show_ratings_comments() {
    	if (is_admin()) {
    		remove_filter( 'pre_get_comments', 'et_pre_get_comments_filter' );
    	}
    }

    Here I have introduced the bug in a post (basically I vote on several different devices, it usually fails after the third). But depending on the duration of the cache they may see it functional, but eventually it gets stuck again:

    https://brevenoticia.cl/nacional/15-09-2023/making-bug-for-support/

    Sometimes I can “speed up” the problem by rating while logged in, this action causes a bug in the post instantly (unfortunately it also gets stuck among disconnected visitors) Where could the problem be? What I can do?

    Any advice or help is very welcome

    Report Number: SSCTMWME

    Thank you so much !

    Greetings

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support qtwrk

    (@qtwrk)

    the rating only shows up after the user posted it ?

    does it set cookie or something we can use ?

    Thread Starter hernan2022

    (@hernan2022)

    Thanks for answering. It is a simple rating system, the visitor who enters for the first time should see the 5 gray stars, once a preference has been marked this decision should be maintained. When a post is bugged, the news visitor sees a marked star already (for example, in the image capture the new devices saw 4 stars marked without having marked them themselves)

    My level is very basic, I wouldn’t know if there are cookies involved. Reviewing the ratings.php file (the dropbox file) I have also come to think that it is a problem in the function that rescues the visitor’s IP. I think I’m going to insist on Elegant Themes, they can’t leave me with nothing, at least they should help me understand the problem I think

    Plugin Support qtwrk

    (@qtwrk)

    you made it no-cache , still experience issue with no-cache ?

    Thread Starter hernan2022

    (@hernan2022)

    Yes, I can confirm that the problems go away when I disable LiteSpeed

    I have once again insisted on Elegant Themes, they are very reluctant to speculate on the causes or alternatives to follow. However, after insisting, they explained to me that the rating information is stored in template-tags.php and that it is finally stored in a database with core WordPress functions. I attach this file also in dropbox

    https://www.dropbox.com/scl/fi/09poqqptnnzk2dj218xvk/template-tags.php?rlkey=kjsrzjyf2ivj952p88qqbm98r&dl=0

    The truth is I’m a little stunned. Maybe the problem is simpler and I would just have to ensure that that page is purged when someone leaves a rating (that is, the same as when a comment is approved in wordpress)

    The ratings.php file apparently has an approval function (extra_rating_pre_comment_approved) (ratings are approved automatically) even a little further down there is a php filter already created(pre_comment_approved). Maybe with this I could create a purge function to the page that received rating?

    I’m a little overwhelmed any advice is very welcome, thank you very much

    Plugin Support qtwrk

    (@qtwrk)

    if you want to purge the page cache when getting rating , you can add this code inside that function

    if (defined('LSCWP_V')){
    do_action( 'litespeed_purge_post', $post_id );
    }

    you need to update the $post_id to the post ID though

    Thread Starter hernan2022

    (@hernan2022)

    It is difficult to me modify the file in Child Theme (parent defines it as a core file)

    So I am transforming the idea into a snippet to copy into functions.php. I have come to this:

    function custom_purge($commentdata) {
        if (defined('LSCWP_V')) {
            $post_id = $commentdata['comment_post_ID'];
            do_action('litespeed_purge_post', $post_id);
        }
    }
    
    add_action('pre_comment_approved', 'custom_purge', 10, 1);

    But it still doesn’t work, I sense that I must be close to the solution. For example, I visit the website from my phone and see the rating already selected (bug). I manually purge the cache of everything, refresh on my phone and can vote rating

    I see the correct code snippet, it is consistent with the information managed by ratings.php I think

    I don’t know what to do

    Thread Starter hernan2022

    (@hernan2022)

    My code is wrong, I’ve done debug testing and I’m not actually capturing the post id

    I see it logical but it is not correct

    Thread Starter hernan2022

    (@hernan2022)

    Thanks for the push, I already solved the problem (with the help of Elegant Themes support, to be fair they finally helped me too). The final code is something similar to this:

    function custom_purge_rating($approved, $comment_data) {
        // Check if the comment is approved (status '1' means approved)
        if ($approved == '1') {
            $post_id = $comment_data['comment_post_ID'];
            do_action('litespeed_purge_post', $post_id);
        }
        return $approved;
    }
    
    add_filter('pre_comment_approved', 'custom_purge_rating', 10, 2);

    It was too difficult to get the post id from the theme’s functions or attributes. In this code we would be using attributes from the WordPress core

    Thank you very much, regards

    Thread Starter hernan2022

    (@hernan2022)

    I have failed miserably. While automatic purging made it more likely that the correct version would be displayed, it failed again

    I had not understood the nature of the problem. What actually happens is that it always works fine UNTIL someone reviews the post that already rated it again. At that moment the server verifies that the user has already given a rating and shows the rating that was given

    So far so good, but the server is going to cache the version it showed to the person who revisited its own rating. The post will appear with a given rating for everyone else, that’s why it had so many inconsistencies and I didn’t know why it was due

    Due to a date issue I am disabling this functionality, I prefer to show simplicity rather than show errors or failures. But in the medium or long term I would like to consider implementing it again

    An idea or path for the future would be ideal, in any case thanks

    Plugin Support qtwrk

    (@qtwrk)

    alright, please create a ticket by mail to support at litespeedtech.com with reference link to this topic , we will investigate further.

    Thread Starter hernan2022

    (@hernan2022)

    Thank you so much. I will do it in a little more time, I can even provide a testing environment with the theme already prepared and documenting in detail how to induce the problem. I will prepare everything that can be useful

    Thank you very much for the support

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Rating problem in Extra Theme’ is closed to new replies.