Keeping users logged in, membership 2 or ultimate branding? How?

I noticed that the links in an article on wpmu about keeping users logged in eternially went to the Ultimate Branding plugin, which I had been planning to utilize on our website. I also run Membership 2, which is used for our members to log into the community.

My goal is to make it so that they login and never have to login again, as many are complaining about that when using their phones.

What would be the advised direction for me to take to accomplish this given that I use Membership 2 and Ultimate Branding?

  • Adam Czajczyk

    Hi Luis,

    I hope you're well today and thank you for your question!

    That's actually a bit more complex than just a Membership 2 and/or Ultimate Branding settings. The way user logging in/authorization works is that after the user logs in, he/she is logged in - by default- only as long as the login cookie exists. That's got an limited "life time". Furthermore, switching to other browser, not to mention device, means that this login cookie won't be "carried over" with the user and they'll need to login again.

    That's why there's "remember me" checkbox on a login form. It sets longer cookie lifetime so if a user is using the same device and browser all the time - and is a regular user - it essentially means that he/she doesn't have to login again. That is until e.g. browser cookies/cache are cleared.

    The Ultimate Branding can be used to "keep user logged in" in that sense that it can e.g. help you hide the admin toolbar from logged in users (thus hiding the toolbar's "logout" link). The Membership 2 Pro plugin is an access control but it doesn't let you control "login cookie".

    That being said, we cold use a little trick here that would set auth cookie ("login cookie") lifetime to, let's say, a year. If a user loads the site using the same browser and device within this year from the last visit and browser cookies has not been purged, that should do the job in most cases.

    To achieve this, you would want to add following code to the "functions.php" file of your current theme:

    add_filter( 'auth_cookie_expiration', 'wpmu_eternal_auth_cookie' );
    function wpmu_eternal_auth_cookie( $expiration_seconds ) {
    // calculation: 60 sec * 60 min * 24h * 365 days = 1 year
       return 31556926;
    }

    I hope that helps :slight_smile:

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.