2

How to logout a user when he closes the tab/window ?

If no, it is possible to clear the session after specific time? How to do that?

2
  • If I am reading the question right, this is either a Javascript question and off-topic here, or a (near) duplicate of this question: wordpress.stackexchange.com/questions/108399/…
    – s_ha_dum
    Commented Nov 10, 2013 at 14:45
  • It doesn't seem to work properly on custom login. When Session expires, I'm unable to login .
    – rgb
    Commented Nov 11, 2013 at 15:28

1 Answer 1

2

I worked long on this one. It is because of the WordPress remember me. Use this code in your theme's functions.php and it should fix your issue:

function myplugin_cookie_expiration( $expiration, $user_id, $remember ) {
    return $remember ? $expiration : 180;
}
add_filter( 'auth_cookie_expiration', 'myplugin_cookie_expiration', 99, 3 );
1
  • hey is it possible to add the user expiration time for a user role exemple for client role?
    – Samuel
    Commented Dec 31, 2021 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.