• Resolved jimk1416

    (@jimk1416)


    I’ve had issues where if I don’t purge the cache right before I logout the pages do not load correctly. Then I have to log back in and purge the caches for all pages.

    Is there a way to clear purge all caches automatically on logout?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It sounds like you’re experiencing some issues with cache not clearing properly when you log out. Let me explain how WP-Optimize handles cache purging and how you can set it up to clear automatically on logout.

    WP-Optimize automatically purges cache in several situations:

    • When you publish or update content.
    • When you change or update themes or plugins.
    • When you edit widgets or menus.
    • When you save customizer settings or change cache settings.
    • When comments are approved or their status changes.
    • When updating the stock quantity of WooCommerce products or when they go on sale (Premium feature).
    • Based on the cache lifespan setting, which purges cache at regular intervals.

    While automatic cache purging on logout isn’t a built-in feature, you can easily add it with a bit of custom code. Here’s how:

    • Add to Theme’s functions.php:
    function clear_cache_on_logout() {
    if (class_exists('WP_Optimize')) {
    WP_Optimize()->get_page_cache()->purge();
    }
    }
    add_action('wp_logout', 'clear_cache_on_logout');

    This will ensure that the cache is automatically purged whenever a user logs out, preventing the issues you are experiencing with incorrect page loads after logging out. If you need further assistance, please let me know!

    • This reply was modified 1 year, 11 months ago by wpmansour.
    Thread Starter jimk1416

    (@jimk1416)

    Perfect. This is exactly what I was hoping for.
    Thanks for the quick reply.

    Great to hear that the solution worked perfectly for you! 😀

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Clear cache on logout’ is closed to new replies.