bp_xprofile_get_hidden_field_types_for_user( int $displayed_user_id, int $current_user_id )
Get the visibility levels that should be hidden for this user pair.
Description
Field visibility is determined based on the relationship between the logged-in user, the displayed user, and the visibility setting for the current field. (See bp_xprofile_get_hidden_fields_for_user().) This utility function speeds up this matching by fetching the visibility levels that should be hidden for the current user pair.
See also
Parameters
- $displayed_user_id
-
(Required) The id of the user the profile fields belong to.
- $current_user_id
-
(Required) The id of the user viewing the profile.
Return
(array) An array of visibility levels hidden to the current user.
Source
File: bp-xprofile/bp-xprofile-functions.php
function bp_xprofile_get_hidden_field_types_for_user( $displayed_user_id = 0, $current_user_id = 0 ) {
// Current user is logged in.
if ( ! empty( $current_user_id ) ) {
// Nothing's private when viewing your own profile, or when the
// current user is an admin.
if ( $displayed_user_id == $current_user_id || bp_current_user_can( 'bp_moderate' ) ) {
$hidden_levels = array();
// If the current user and displayed user are friends, show all.
} elseif ( bp_is_active( 'friends' ) && friends_check_friendship( $displayed_user_id, $current_user_id ) ) {
$hidden_levels = array( 'adminsonly', );
// Current user is logged in but not friends, so exclude friends-only.
} else {
$hidden_levels = array( 'friends', 'adminsonly', );
}
// Current user is not logged in, so exclude friends-only, loggedin, and adminsonly.
} else {
$hidden_levels = array( 'friends', 'loggedin', 'adminsonly', );
}
/**
* Filters the visibility levels that should be hidden for this user pair.
*
* @since BuddyPress 2.0.0
*
* @param array $hidden_fields Array of hidden fields for the displayed/logged in user.
* @param int $displayed_user_id ID of the displayed user.
* @param int $current_user_id ID of the current user.
*/
return apply_filters( 'bp_xprofile_get_hidden_field_types_for_user', $hidden_levels, $displayed_user_id, $current_user_id );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.8.2 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.