您可以通过调用wp\\u logout()函数以编程方式在Wordpress中注销用户。要将此应用于4小时规则,请考虑以下代码:
function user_update_login($login) {
// function fires when a user logs in
global $user_ID;
$user = get_userdatabylogin($login);
// save the current time when the user logged in
update_usermeta( $user->ID, \'last_login\', time() );
}
add_action(\'wp_login\',\'user_update_login\');
function check_time_limit() {
// populate the user objects
get_currentuserinfo();
global $user_ID;
// only run if the user is logged in
if($user_ID) {
// get the last login time
$last_login = get_user_meta($user_ID, \'last_login\', TRUE);
// if the current time is greater than the last login
// + 14400 seconds (4 hours) the user will be logged out
if(time() > ($last_login + 14400)) {
wp_logout();
}
}
}
check_time_limit();
将此代码放入函数中。php文件将在4小时后注销所有用户。如果只想将此规则应用于特定页面等,还可以将check\\u time\\u limit()的调用移动到主题中的任何位置。