Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change session expire time in WordPress?

I want expire the session if user (admin) is inactive for 15 minute in WordPress site,

can anyone tell me what is the default session expiry time in WordPress? and how to change that default expire time.

like image 363
mack Avatar asked Feb 08 '12 10:02

mack


People also ask

Why does my WordPress session expire?

WordPress sessions are programmed to timeout after 48 hours. This timeout won't be the cause of frequent "WordPress Session Expired" errors, but changing it can reduce unneeded logins. To extend the duration of a WordPress session you must create a child theme and modify the functions.

How do I set session timeout?

Click Container Settings > Session management > Set Timeout. Enter the desired timeout value in minutes.

What causes session to expire?

If your Internet connection is unstable, periodically disconnecting and reconnecting, it can cause a website session to expire. When the Internet connection is lost the website connection can be terminated, resulting in a session expired message if you try to access any page after the Internet reconnects.

Does session expire refresh?

refreshing a web page will not expire or create a new session in server. session is a user(client) based variable will create and store when the user first request send to the web server. so when you refresh a currently rendered page, only expiration time will reset.


1 Answers

Simply add this code in your theme's functions.php:

add_filter('auth_cookie_expiration', 'my_expiration_filter', 99, 3);
function my_expiration_filter($seconds, $user_id, $remember){

    //if "remember me" is checked;
    if ( $remember ) {
        //WP defaults to 2 weeks;
        $expiration = 14*24*60*60; //UPDATE HERE;
    } else {
        //WP defaults to 48 hrs/2 days;
        $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;
}
like image 154
Reza Mamun Avatar answered Oct 19 '22 01:10

Reza Mamun