• Resolved hellothanos

    (@hellothanos)


    Hello,

    Really enjoying the plugin! I’m running into an issue with cached pages though. After I vote the numbers stay the same and I have to clear the cache manually. I’m using WP Rocket.
    Is there a way for the cache of the page to be cleared right after the user votes?
    I’m thinking that if there is a hook, I could do it with php.. but I can’t see any in the docs.

    Any help would be deeply appreciated!

    Thanks,
    Thanos

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Pixelbart

    (@pixelbart)

    Hello @hellothanos

    I’m not a WP-Rocket specialist unfortunately, but you can try the following. Simply in the functions.php or similar:

    apply_filters('helpful_pre_save_vote', 'helpful_rocket_pre_save_vote', 99, 2);
    
    function helpful_rocket_pre_save_vote($response, $post_id)
    {
        $pages_to_clean_preload = [];
    
        $pages_to_clean_preload[] = get_the_permalink($post_id);
    
        if (function_exists('rocket_clean_post')) {
            rocket_clean_post($post_id);
        }
    
        if (function_exists('get_rocket_option')) {
    
            if (1 == get_rocket_option('manual_preload')) {
                $args = [];
    
                if (1 == get_rocket_option('cache_webp')) {
                    $args['headers']['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
                    $args['headers']['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
                }
    
                helpful_rocket_preload_page($pages_to_clean_preload, $args);
    
                if (1 == get_rocket_option('do_caching_mobile_files')) {
                    $args['headers']['user-agent'] = 'Mozilla/5.0 (Linux; Android 8.0.0;) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Mobile Safari/537.36';
                    helpful_rocket_preload_page($pages_to_clean_preload, $args);
                }
            }
        }
    
        return $response;
    }
    
    function helpful_rocket_preload_page($pages_to_preload, $args)
    {
        foreach ($pages_to_preload as $page_to_preload) {
            wp_remote_get(esc_url_raw($page_to_preload), $args);
        }
    }

    See: https://docs.wp-rocket.me/article/494-how-to-clear-cache-via-cron-job

    Stay healthy!

    Greetings Kevin

    Thread Starter hellothanos

    (@hellothanos)

    helpful_pre_save_vote was what I was looking for, thank you!
    And thank you for the extra effort to suggest the Wp Rocket solution ??

    Best,
    Thanos

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘page caching issue’ is closed to new replies.