BP_XProfile_Group::fetch_default_visibility_levels()

Fetch the admin-set preferences for all fields.

Description

Return

(array) $default_visibility_levels An array, keyed by field_id, of default visibility level + allow_custom (whether the admin allows this field to be set by user)

Source

File: bp-xprofile/classes/class-bp-xprofile-group.php

755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
public static function fetch_default_visibility_levels() {
    global $wpdb;
 
    $default_visibility_levels = wp_cache_get( 'default_visibility_levels', 'bp_xprofile' );
 
    if ( false === $default_visibility_levels ) {
        $bp = buddypress();
 
        $levels = $wpdb->get_results( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" );
 
        // Arrange so that the field id is the key and the visibility level the value.
        $default_visibility_levels = array();
        foreach ( $levels as $level ) {
            switch ( $level->meta_key ) {
                case 'default_visibility' :
                    $default_visibility_levels[ $level->object_id ]['default']      = $level->meta_value;
                    break;
                case 'allow_custom_visibility' :
                    $default_visibility_levels[ $level->object_id ]['allow_custom'] = $level->meta_value;
                    break;
            }
        }
 
        wp_cache_set( 'default_visibility_levels', $default_visibility_levels, 'bp_xprofile' );
    }
 
    return $default_visibility_levels;
}

Changelog

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.