導讀:搭建網站搭建網站在WordPress的用戶管理問題中發現WordPress有一個很頭疼的問題,那就是,WordPress居然可以多個人同事登陸一個賬號,不知道目前的4.8版本是網站技術支持國外技術網站。

在WordPress的用戶管理問題中發現WordPress有一個很頭疼的問題,那就是,WordPress居然可以多個人同事登陸一個賬號,不知道目前的4.8版本是否還允許,這里也不在測試,直接分享一段代碼,實現:WordPress 禁止多人同時登錄一個用戶賬號。
WordPress 禁止多人同時登錄一個用戶賬號
這里推薦的功能插件為:Prevent Concurrent Logins和Wp Single Login點擊即可直接下載。
如果你不想用插件,這里是代碼版,添加到function.php即可:
以下分別為兩個插件提取的代碼版!
Prevent Concurrent Logins提取:
function?pcl_user_has_concurrent_sessions()?{
????return?(?is_user_logged_in()?&&?count(?wp_get_all_sessions()?)?>?1?);
}
/**
?*?Get?the?user's?current?session?array
?*
?*?@return?array
?*/
function?pcl_get_current_session()?{
????$sessions?=?WP_Session_Tokens::get_instance(?get_current_user_id()?);
????return?$sessions->get(?wp_get_session_token()?);
}
/**
?*?Only?allow?one?session?per?user
?*
?*?If?the?current?user's?session?has?been?taken?over?by?a?newer
?*?session?then?we?will?destroy?their?session?automattically?and
?*?they?will?have?to?login?again?to?continue.
?*
?*?@action?init
?*
?*?@return?void
?*/
function?pcl_disallow_account_sharing()?{
????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();
????}
}
add_action(?'init',?'pcl_disallow_account_sharing'?);
Wp Single Login提取:
關鍵詞標簽: 搭建網站 代碼 賬號
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-07-23 ,文章WordPress 禁止多人同時登錄一個用戶賬號(代碼版主要講述賬號,代碼,搭建網站網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_35098.html