【发布时间】:2012-02-29 18:32:19
【问题描述】:
如果用户(管理员)在 WordPress 站点中闲置 15 分钟,我希望会话过期,
谁能告诉我 WordPress 的默认会话到期时间是多少?以及如何更改默认过期时间。
【问题讨论】:
如果用户(管理员)在 WordPress 站点中闲置 15 分钟,我希望会话过期,
谁能告诉我 WordPress 的默认会话到期时间是多少?以及如何更改默认过期时间。
【问题讨论】:
只需将此代码添加到主题的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;
}
【讨论】:
if ( user_can( $user_id, 'manage_options' ) ) { $expiration = 2*60*60; }