If a logged-out user visits a page, and then revisit it when logged-in, it will show the cached version. There's a closed question similar to this with an answer that suggests to set Cache Control to no-cache
. This will affect logged-out users, which defeats the purpose of caching in the first place.
The problem
When using page/browser caching with T3 Total Cache or likely other caching plugins, if you have already visited a page when logged out, you will be presented with the same logged-out version of the page, unless if you refresh the page.
You can reproduce this issue by:
Have caching enabled. Then, in incognito mode, visit a post.
Login to the site and then manually type the URL of that post into the address bar. The logged-out version of the page should appear.
This is obviously an issue you have any features available for logged-in users only (like comments, voting etc)...
Potential solution
The only potential solution I have is to add a query variable to the URL on every request. For example by adding a random value:
$key = rand();
$new_url = esc_url( add_query_arg( 'foo', $key ) );
I know how to manually add this variable to single queries but instead of altering every single instant of links, is there a way how to force this to every URL for logged-in users?
Note: I'm not sure if this is the ideal approach to solve this problem (it feels quite desperate) so feel free to post an answer with a better solution.
if (is_user_logged_in()) { header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); }