如何在 WordPress 中更改会话过期时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9191359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:53:00 来源:igfitidea点击:
How to change session expire time in WordPress?
提问by mack
I want expire the session if user (admin) is inactive for 15 minute in WordPress site,
如果用户(管理员)在 WordPress 站点中处于非活动状态 15 分钟,我想使会话过期,
can anyone tell me what is the default session expiry time in WordPress? and how to change that default expire time.
谁能告诉我 WordPress 中的默认会话到期时间是多少?以及如何更改默认过期时间。
回答by Reza Mamun
Simply add this code in your theme's functions.php:
只需在主题的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;
}