0
我使用BuddyPress的具有多個基團。每個用戶也可以作爲成員加入多個組。我使用自定義配置文件字段地址。每個成員都可以選擇,誰可以查看他的個人資料。此嘗試基於插件'User Profile Visibility Manager'。現在我需要一個額外的選項:查看配置文件「組成員只有」如果檢查構件是一組
我的計劃是:
獲得「遊客」的USER_ID - 可以完美兼容:
$ user_id_visitor = bp_loggedin_user_id();
獲取的個人資料所有者的USER_ID - 可以完美兼容:
$ user_id_profile_owner = bp_displayed_user_id();
獲取由配置文件owner's USER_ID組(S):
在這裏,從來就嘗試了很多。通過此功能,我可以打印「個人資料所有者」所屬的所有羣組。但我不需要打印,它僅僅是一個測試:
function bp_groups_profileowner($user_id_profile_owner) {
global $wpdb;
$groups = $wpdb->get_results($wpdb->prepare("SELECT group_id FROM wp_bp_groups_members WHERE user_id = %d", $user_id_profile_owner));
if ($groups) {
foreach ($groups as $group) {
echo '<li>' . $group->group_id . '</li>';
}
}
- 檢查profile_owner's組(S)的所有成員,並檢查,如果遊客也是成員的組( S)。
我在選擇框新選項:
<option value="groupmembers" <?php echo selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility'));?>><?php _e('Group Members Only','bp-profile-visibility');?></option>
這是代碼片段,從插件,它會檢查並保護用戶帳戶的知名度來:
/**
* Checks and protects user account visibility
* @return type
*/
function check_profile_access(){
if(!bp_is_user() || is_super_admin())
return;
//if we are on user profile page
$privacy = bp_profile_visibility_get_settings(bp_displayed_user_id(), 'bp_profile_visibility');
//if privacy is public, everyone can see
if('public' == $privacy)
return;
$referrer=wp_get_referer();
if($referrer)
$referrer=bp_core_get_root_domain();
//in all other cases, user must be logged in
if(!is_user_logged_in()){
bp_core_add_message(__('Please login to view profile','bp-profile-visibility'),'error');
wp_safe_redirect($referrer);
exit(0);
return ;
}
//if we are here, the person is logged in, let us see if the visibility is set to logged in
if('loggedin' == $privacy)
return ;
//if this is my profile, do not prevent user
if(bp_is_my_profile())
return ;
//now, since we have already tested for login , we just need to test for the friends only and me
if('friends' == $privacy && function_exists('friends_check_friendship') && friends_check_friendship(bp_displayed_user_id(), get_current_user_id()))
return;
//now, we just need to test for the group members
if('groupmembers' ...)
//if we are here, don't show the profile
bp_core_add_message(__('This User\'s privacy settings does not allow you to view the profile.','bp-profile-visibility'),'error');
wp_safe_redirect($referrer);
exit(0);
return ;
}