• I’m developing a membership-based site that has some conditional elements in the theme’s header, depending on whether or not the user is logged in. I looked at the Wiki for the plugin and have created an event-based function in my theme that I want to clear Varnish cache when the user logs in and logs out:

    function my_varnish_purge_events( $actions ) {
    	$myactions = array(
    	'wp_login',	// When a user logs in
            'wp_logout', // When a user logs out
    	);
    	array_merge( $actions, $myactions ) ;
    	return $actions;
    }
    add_filter( 'varnish_http_purge_events', 'my_varnish_purge_events' );

    It seems to work like a charm when the user logs in. But, even after logging out, I’m still seeing elements that only logged in users should see (like a logout button in the header, for example).

    Am I taking the wrong approach here or should I tie this in to a different event?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    If you’re trying to empty the cache for all pages, you’ll want to hook into both the purge events and the purge all functions but …

    That sounds REALLY computationally expensive, and something that shouldn’t be needed since logged in users aren’t cached (except for CSS/JS). You shouldn’t need to flush the cache when logging in, since a logged in user won’t get the cached page at all.

    How are you making the logout button in the header? I wonder if that’s what needs special attention.

    Thread Starter Eric Karkovack

    (@karks88)

    Thanks! I definitely don’t need to empty everything. I have the logout link setup this way:

    <a class="logout-link" href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout"><i class="fas fa-sign-out-alt"></i> Logout</a>

    The link is set to only show when a user is logged in. But after logging out, it still displays and takes a hard refresh of the page get rid of it. I notice that if I turn off Varnish via the plugin, it works the way I intended.

    Thread Starter Eric Karkovack

    (@karks88)

    Still having this issue – do you have any suggestions?

    Plugin Contributor Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    But after logging out, it still displays and takes a hard refresh of the page get rid of it.

    Sorry I don’t know why I never got alerts but … That’s your browser cache, not the plugin ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Purging Current Page on Logout’ is closed to new replies.