1

I have a site that allows user registration and login but not via the standard wp-login.php etc - it's all done within the theme and a bit of s2member as well.

I've been encountering problems where, with page caching enabled, my code shows either a login button or a 'your account' button, showing cached material.

I use the below code to decide which button is shown depending on whether the right user level member is logged in.

<?php if (current_user_is("s2member_level1")) : ?>
    <?php
        $current_user = wp_get_current_user();
        $redirect = '&amp;redirect_to='.urlencode(wp_make_link_relative(get_option('siteurl')));
        $uri = wp_nonce_url( site_url("wp-login.php?action=logout$redirect", 'login'), 'log-out' );
    ?>
    <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown">My Account</a>
        <ul class="dropdown-menu">
            <li><a href="<?= $uri; ?>">Logout</a></li>
            <li><a href="<?= get_permalink(x); ?>">Edit Account</a></li>
        </ul>
    </li>
<?php else : ?>
    <li class="login-button">
        <a class="btn-lg" href="<?= get_permalink(x); ?>">Member Login</a>
    </li>
<?php endif; ?>

However, with page caching enabled this has all sorts of problems.

I was looking at the Fragment Caching notes in W3TC's FAQ section but it looks like it has a major failing - it says:

Be aware that WordPress functions will not be available.

So, if I understand it correctly, that pretty much stops me from being able to use fragment caching.

As the member login/my account button is ever-present in the site main nav I've just disabled page caching entirely for the time being.

Is the only option for me to integrate some form of AJAX approach for handling dynamic sections dependent on auth/guest status?

1 Answer 1

3

This is a feature. You can try to disable caching for logged in users, but if it is in the main nav this still won't help as according to the settings screen:

Don't cache pages for logged in users

Unauthenticated users may view a cached version of the last authenticated user's view of a given page. Disabling this option is not recommended.

There are also some other questions for that issue that might clear this up further:

Showing as logged in after logout (W3 Total Cache issue)

https://stackoverflow.com/questions/19441226/w3-total-cache-still-cached-when-user-logging-by-nicety-login

2
  • So really I'm looking at needing to use AJAX to handle the various conditional logged in sections? I tried using the "Don't cache pages for logged in users" but I must have misunderstood how it works - I assumed that logged in users just wouldn't see cached content at all, but I guess that's not how it works.. back to the drawing board! Feb 18, 2014 at 3:31
  • 1
    Think about it. What you want is that one URL looks different in different situations while caching it to always serve the same content. There is just no way this could work...
    – kraftner
    Feb 18, 2014 at 9:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.