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?
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?
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 );
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
return YEAR_IN_SECONDS;
. Additionally, that filter also passes if the user checkedremember 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 ♦ Commented Feb 27, 2019 at 12:43