/** * Fetch an array of the xprofile fields that a given user has marked with certain visibility levels * * @since BuddyPress (1.6.0) * @see bp_xprofile_get_hidden_fields_for_user() * * @param int $user_id The id of the profile owner * @param array $levels An array of visibility levels ('public', 'friends', 'loggedin', 'adminsonly' etc) to be * checked against * @return array $field_ids The fields that match the requested visibility levels for the given user */ 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; }