如何在 WordPress 中更改会话过期时间? [英] How to change session expire time in WordPress?

查看:44
本文介绍了如何在 WordPress 中更改会话过期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户(管理员)在 WordPress 站点中处于非活动状态 15 分钟,我想使会话过期,

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

谁能告诉我 WordPress 的默认会话到期时间是多少?以及如何更改默认过期时间.

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

推荐答案

只需将此代码添加到主题的functions.php:

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;
}

这篇关于如何在 WordPress 中更改会话过期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆