Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/10/2014 04:29:06 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce xprofile_get_field_visibility_level()

This is a simple function for grabbing the visibility level attached to a given
field by a specific user, sensitive to admin-provided defaults and override
settings.

See #4636

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r7812 r7836  
    288288}
    289289
     290/**
     291 * Get the visibility level for a field.
     292 *
     293 * @since BuddyPress (2.0.0)
     294 *
     295 * @param int $field_id The ID of the xprofile field.
     296 * @param int $user_id The ID of the user to whom the data belongs.
     297 * @return string
     298 */
     299function xprofile_get_field_visibility_level( $field_id = 0, $user_id = 0 ) {
     300    $current_level = '';
     301
     302    if ( empty( $field_id ) || empty( $user_id ) ) {
     303        return $current_level;
     304    }
     305
     306    $current_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true );
     307    $current_level  = isset( $current_levels[ $field_id ] ) ? $current_levels[ $field_id ] : '';
     308
     309    // Use the user's stored level, unless custom visibility is disabled
     310    $field = new BP_XProfile_Field( $field_id );
     311    if ( isset( $field->allow_custom_visibility ) && 'disabled' === $field->allow_custom_visibility ) {
     312        $current_level = $field->default_visibility;
     313    }
     314
     315    // If we're still empty, it means that overrides are permitted, but the
     316    // user has not provided a value. Use the default value.
     317    if ( empty( $current_level ) ) {
     318        $current_level = $field->default_visibility;
     319    }
     320
     321    return $current_level;
     322}
     323
    290324function xprofile_delete_field_data( $field, $user_id ) {
    291325    if ( is_numeric( $field ) )
Note: See TracChangeset for help on using the changeset viewer.