bp_xprofile_get_fields_by_visibility_levels( int $user_id, array $levels = array() )
Fetch an array of the xprofile fields that a given user has marked with certain visibility levels.
Description
See also
Parameters
- $user_id
-
(Required) The id of the profile owner.
- $levels
-
(Optional) An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be checked against.
Default value: array()
Return
(array) $field_ids The fields that match the requested visibility levels for the given user.
Source
File: bp-xprofile/bp-xprofile-functions.php
function bp_xprofile_get_fields_by_visibility_levels( $user_id, $levels = array() ) { if ( !is_array( $levels ) ) { $levels = (array)$levels; } $user_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); // Parse the user-provided visibility levels with the default levels, which may take // precedence. $default_visibility_levels = BP_XProfile_Group::fetch_default_visibility_levels(); foreach( (array) $default_visibility_levels as $d_field_id => $defaults ) { // If the admin has forbidden custom visibility levels for this field, replace // the user-provided setting with the default specified by the admin. if ( isset( $defaults['allow_custom'] ) && isset( $defaults['default'] ) && 'disabled' == $defaults['allow_custom'] ) { $user_visibility_levels[$d_field_id] = $defaults['default']; } } $field_ids = array(); foreach( (array) $user_visibility_levels as $field_id => $field_visibility ) { if ( in_array( $field_visibility, $levels ) ) { $field_ids[] = $field_id; } } // Never allow the fullname field to be excluded. if ( in_array( 1, $field_ids ) ) { $key = array_search( 1, $field_ids ); unset( $field_ids[$key] ); } return $field_ids; }
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.