BP_XProfile_Group::fetch_visibility_level( int $user_id, array $fields = array() )
Fetch the field visibility level for the fields returned by the query.
Description
Parameters
- $user_id
-
(Required) The profile owner's user_id.
- $fields
-
(Optional) The database results returned by the get() query.
Default value: array()
Return
(array) $fields The database results, with field_visibility added
Source
File: bp-xprofile/classes/class-bp-xprofile-group.php
public static function fetch_visibility_level( $user_id = 0, $fields = array() ) {
// Get the user's visibility level preferences.
$visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
foreach( (array) $fields as $key => $field ) {
// Does the admin allow this field to be customized?
$visibility = bp_xprofile_get_meta( $field->id, 'field', 'allow_custom_visibility' );
$allow_custom = (bool) ( 'disabled' !== $visibility );
// Look to see if the user has set the visibility for this field.
if ( ( true === $allow_custom ) && isset( $visibility_levels[ $field->id ] ) ) {
$field_visibility = $visibility_levels[ $field->id ];
// If no admin-set default is saved, fall back on a global default.
} else {
$fallback_visibility = bp_xprofile_get_meta( $field->id, 'field', 'default_visibility' );
/**
* Filters the XProfile default visibility level for a field.
*
* @since BuddyPress 1.6.0
*
* @param string $value Default visibility value.
*/
$field_visibility = ! empty( $fallback_visibility )
? $fallback_visibility
: apply_filters( 'bp_xprofile_default_visibility_level', 'public' );
}
$fields[ $key ]->visibility_level = $field_visibility;
}
return $fields;
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.6.0 | 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.