How can I extend wordpress login sessions to a month so that it doesn’t automatically ask for login after 48 hours?

I am basically testing some program with wordpress and around 48 hours it fails and I’m pretty sure it has to do with the session id... So please help me extend it to at least a month!

有帮助吗?

解决方案

By default the login cookie lasts for

  • 14 days if you tick 'remember me'
  • 48 hours if you don't

So as a short term fix you probably want to tick 'remember me', and to extend that to 30 days you can add an auth_cookie_expiration filter e.g.

function auth_cookie_expiration_30_days( $seconds, $user_id, $remember_me ) {
    if ( $remember_me ) {
        return 30 * DAY_IN_SECONDS;
    }
    
    return $seconds;
}
add_filter( 'auth_cookie_expiration', 'auth_cookie_expiration_30_days', 10, 3 );

As you can see you can set per-user-ID durations and you can change the don't-remember-me time here too if you want, although above I'm leaving that as the default.

许可以下: CC-BY-SA归因
scroll top