wordpress禁止用户在不同地点同时登录,管理员除外。
function pcl_user_has_concurrent_sessions()
{return (is_user_logged_in() && count(wp_get_all_sessions()) > 2);
}add_action("init", function () {// 除了管理员,其他人不允许多地同时登陆。if (!current_user_can("manage_options")) {if (!pcl_user_has_concurrent_sessions()) {return;}$newest = max(wp_list_pluck(wp_get_all_sessions(), "login"));$session = pcl_get_current_session();if ($session["login"] === $newest) {wp_destroy_other_sessions();} else {wp_destroy_current_session();}}
});
原文
http://www.chudafu.com/jianzhan/4766.html