如何解决如何在多站点上隔离 Buddypress 会员页面?
感谢 LH Buddypress Multi Network 插件,我在多网络 WordPress 安装(WordPress 多站点)中有一个 BuddyPress 社交网络。
如何防止人们从其他博客访问个人资料页面?
例如:
teacherSite
、teacherUser
studentSite
、studentUser
我限制非会员访问网站。
teacherUser
只能在 teacherSite
上连接。
而且他在目录中看不到其他博客的其他用户。
如果 studentUser
知道 teacherUser
的用户名,或者如果他发现或测试...
他可以去:
studentSite.domain.com/members/teacherUser/
即使 teacherUser
没有链接到 teacherUser
,他也可以看到 studentSite
的个人资料。
幸运的是,除了姓名和头像之外,没有其他信息(因为其他所有内容都很好地隔离)。
但是他还是可以发起连接请求或者给他发私信!
teacherUser
不会在 teacherSite
上看到任何通知。但他可能会收到一封电子邮件,该电子邮件会将他重定向到 studentSite
,而无法连接到该电子邮件。
如何避免这种情况?
解决方法
我猜 BuddyPress 的用户管理系统与 WordPress 有点相同。
我们可以将当前用户角色与查询到的用户角色进行比较。如果它们不同,我们会阻止并重定向。
<?php
/**
* Compare the queried user role with the current user role.
* If both don't match restrict profile access and redirect to current user profile.
*
* Case exceptions:
* - IF the current user IS the queried user.
* - IF the current user IS an Admin or Super-Admin.
*/
add_action( 'wp',function() {
if ( is_author() && get_queried_object() instanceof \WP_User ) {
if ( reset( get_queried_object()->roles ) === reset( wp_get_current_user()->roles ) || get_current_user_id() === get_queried_object_id() || current_user_can( 'manage_options' ) ) { // ... @see https://wordpress.org/support/article/roles-and-capabilities/#capability-vs-role-table
return;
} else {
header( 'Refresh: 2; ' . esc_url( get_author_posts_url( get_current_user_id() ) ) );
$args = array(
'back_link' => true,);
wp_die( "Error,Restricted access. You're not allowed to view this profile.",'Error,Restricted access',$args );
};
};
} );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。