0

I am using this function which is supposed to prevent wordpress from automatically logging me out. However, I am still being logged out every so often.

function my_logged_in( $expirein ) {
   return 31556926; // 1 year in seconds
}
add_filter( 'auth_cookie_expiration', 'my_logged_in' );

Is there another solution to this?

  • Have you verified in your browser dev tools that the cookie expiration is indeed being set? – Tom J Nowell Feb 27 at 12:43
  • Also, there are predefined macros for time lengths, e.g. return YEAR_IN_SECONDS;. Additionally, that filter also passes if the user checked remember me, but that functionality would be broken with that filter. Where is your filter placed? functions.php? A plugin? Is it itself ran on a hook? Have you verified that it gets called? – Tom J Nowell Feb 27 at 12:43
1

As we know by default WordPress keeps logged in for 48 Hours. If we check "Remember me" while login then it will keep login for 14 Days.

If you want to set the logout timeout you can use this code as:

function wpset_change_cookie_logout( $expiration, $user_id, $remember ) {
    if( $remember && user_can( $user_id, 'manage_options' ) ){
        $expiration = 31556926;
    }
    return $expiration;
}
add_filter( 'auth_cookie_expiration','wpset_change_cookie_logout', 10, 3 );
0

Did you take a look at your session.gc_maxlifetime in your php settings? Also, some operating systems like Debian or Ubuntu have a crontab that flushes sessions. More info here

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.