Keep Users Logged In As Long As I Like

I'm implementing a Kiosk webapp based off WordPress and I have some conditionals which are key, they work based on whether user is logged in or not.

I'm aware that after user clicks "remember me" it will keep them logged in for 14 days.

However, I want to keep users logged in for as long as possible once they log in through the kiosk.

I was maybe thinking 1 month.

Is there any limit to how long I can set? Can I set for 2 months? 3 months? 4 months? I know an actual cookie can be set to more than 10 years, but not sure if WP has it's own limitations on that.

I also found a snippet of code to help me set this but I'm not sure how to know if it works, the article I found it from is 2 years old...

// keep users logged in for longer in wordpress
function wcs_users_logged_in_longer( $expirein ) {
    // 1 month in seconds
    return 2628000;
}
add_filter( 'auth_cookie_expiration', 'wcs_users_logged_in_longer' );

Thank you.

Topic authentication cookies logging filters Wordpress

Category Web


I know this question is old, but incase anyone stumbles across it (like I did).

I've recently had the same problem of wanting to keep users logged into WP, so I've created a plugin to do just that.

Take a look, I hope it helps: https://wordpress.org/plugins/wp-persistent-login/


What you found is actually perfectly accurate. With WP's commitment to backwards compatibility it's not that common for thing to stop working.

This filter is used in wp_set_auth_cookie() to calculate the duration. Resulting value is used in PHP's setcookie().

There is no mention of specifics limits in documentation, so in practice the value is limited by integer range for Unix timestamp (practically at the moment — year 2038 give or take).

So you are pretty set on WP side, but I'd also look into how browsers handle it. I don't think I heard about extra long expiration times used in practice outside of development. So it's not well covered topic.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.