WordPress中禁止多个人同时登录一个账号

WordPress中禁止多个人同时登录一个账号,第1张

概述WordPress建站中,有时我们的网站开放注册,希望会员在里面自由评论发布文章。对于这些开放注册的 WordPress 站点来说,尤其是具有会员购买服务的网站,需要禁止多个人同时登录一个账号

中,有时我们的网站开放注册,希望会员在里面自由评论发布文章。对于这些开放注册的 WordPress 站点来说,尤其是具有会员购买服务的网站,需要禁止多个人同时登录一个账号。下面介绍一下方法。

切换到主题目录,打开 functions.php 文件,加入以下代码:

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' );

当然您也可以下载安装 插件实现同样地效果。

总结

以上是内存溢出为你收集整理的WordPress中禁止多个人同时登录一个账号全部内容,希望文章能够帮你解决WordPress中禁止多个人同时登录一个账号所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/1022716.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存