![](/img/trans.png)
[英]How to show xprofile data in member page and change member page in buddypress?
[英]How to segregate the Buddypress member page on multisite?
感謝 LH Buddypress Multi Network 插件,我在多網絡 WordPress 安裝(WordPress 多站點)中有一個 BuddyPress 社交網絡。
如何防止人們從其他博客訪問個人資料頁面?
例如: teacherSite
、 teacherUser
studentSite
、 studentUser
我已限制非會員訪問網站。 teacherUser
只能在teacherSite
上連接。 而且他在目錄中看不到其他博客的其他用戶。
如果studentUser
知道teacherUser
用戶名,或者他發現或測試......
他可以 go 到:
studentSite.domain.com/members/teacherUser/
即使teacherUser
沒有鏈接到studentSite
,他也可以看到teacherUser
的個人資料。
幸運的是,除了姓名和頭像之外,沒有其他信息(因為其他所有信息都被很好地隔離了)。
但他仍然可以提出連接請求或給他發私信! teacherUser
不會在teacherSite
上看到任何通知。 但他可能會收到一個 email ,這會將他重定向到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 );
};
};
} );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.