$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>functions - Prevent Wordpress Automatic Logout|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - Prevent Wordpress Automatic Logout

matteradmin7PV0评论

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?

Share Improve this question asked Feb 27, 2019 at 12:34 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges 2
  • Have you verified in your browser dev tools that the cookie expiration is indeed being set? – Tom J Nowell Commented Feb 27, 2019 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 Commented Feb 27, 2019 at 12:43
Add a comment  | 

2 Answers 2

Reset to default 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 );

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far