The Chamber Dashboard Member Manager plugin was recently updated to show a member account page which displays the membership details for the logged in users. We have had the member login feature for a while in the Chamber Dashboard plugins, but adding a member account page gave users an easy way to look at their business listing, edit the listing and a lot more. While this was a useful feature for our users, I encountered issues with WordPress caching while working on this feature.
Read more about WordPress caching here.
The member account page also shows the link to edit their businesses. While working on the account page, I constantly encountered the issue of having to re-login every time I visited a new member page on the site. I would login, and when I wanted to edit the business listing, it would not recognize that I was already logged in.
The issue was because it was loading a cached version of the page. When I checked the ‘disable cache’ in the network tab, everything seemed to work well.
I was using the WordPress function is_user_logged_in() to perform actions based on the login status. Checking for the logged in user status was not just enough.
Setting a variable based on whether the user is logged in or not, in the header helped to load the correct version of the page based on the login status of the user. I could then use the $logged variable to load the correct version of the page.
[php]
function cdashmm_check_user_login(){
if ( is_user_logged_in() ) {
$logged = TRUE;
} else {
$logged = FALSE;
}
}
add_action(‘wp_head’, ‘cdashmm_check_user_login’);
[/php]