4

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.

  • I've used that same function with 31556926 for a year, and it works fine with WP 4.2 and with all the browsers I've tried for my localhost sites. Unless, of course, I logout or clear cookies. – markratledge Apr 8 '16 at 19:36
  • @markratledge what was your implementation? Was it like mine? Happen to try it on an Ipad browser? App has a totally different behavior if you're logged out compared to if you're logged in which is why I need this. – Uriahs Victor Apr 8 '16 at 19:46
  • I used the exact same function my own plugin and in functions.php in different themes, and they worked fine; but, I never have tried it on iOS Safari. – markratledge Apr 9 '16 at 1:08
  • If you're concerned about browsers not respecting a cookie with a long expiration date, you could set the login cookie for a month every time the logged-in user requested a page. – Joel Apr 12 '16 at 21:22
3

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.

  • Thanks @Rarst if all it does is set a cookie on the users browser then wouldn't I be ok as long as they dont delete the cookies off the kiosk's browser? – Uriahs Victor Apr 8 '16 at 19:26
  • Probably, but as I said this is not typically done in my experience, so I am not that confident about all the aspects. – Rarst Apr 8 '16 at 19:31
  • Thank you at least I know the snippet works, I guess it comes down to live tests. I don't mind if the cookie just lives for 1 month. But user needs to stay logged in for 1 month (yes they will be using the account several hours a day during that month). Will WP still log out a user even though they are using the account? – Uriahs Victor Apr 8 '16 at 19:35
  • This filter is supposed to set precisely how long until WP will log user out. What will WP do is something you'll have to either test or read through mountain of code to figure out. – Rarst Apr 8 '16 at 19:44
0

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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