0

I was trying to extend the Login Cookie with the following Code

function expiration_filter($seconds, $user_id, $remember){

    //if "remember me" is checked;
    if ( $remember ) {
        //WP defaults to 2 weeks; 14*24*60*60
        $expiration = 10*365*24*60*60; //10 Yrs;
    } else {
        //WP defaults to 48 hrs/2 days; 2*24*60*60
        $expiration = 2*24*60*60; //UPDATE HERE;
    }

    //http://en.wikipedia.org/wiki/Year_2038_problem
    if ( PHP_INT_MAX - time() < $expiration ) {
        //Fix to a little bit earlier!
        $expiration =  PHP_INT_MAX - time() - 5;

    }

    return $expiration;
}
add_filter('auth_cookie_expiration', 'expiration_filter', 99, 3);

The Cookie is set to a date in 10 years (2029) which seems fine, but after 2 weeks the user gets logged out. Maybe I missed something in the Code or there is an extra Hook for everything beyond 2 weeks?

  • 1
    Keep in mind that this won't affect any users who are already logged in. Is that possibly the issue here? – Jacob Peattie May 22 at 10:24
  • No this is not the Issue. I made that change a few months ago, and I have been logged out a few times - and logged in again. So the new Cookie was set. – nuriye Jun 4 at 8:18

Your Answer

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

Browse other questions tagged or ask your own question.