Skip to:
Content

BuddyPress.org

Changeset 6610


Ignore:
Timestamp:
12/10/2012 03:02:27 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Allow profile field visibility to work when viewing register page. Fixes #4456.

File:
1 edited

Legend:

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

    r6518 r6610  
    116116
    117117        $defaults = array(
    118             'profile_group_id'    => false,
    119             'user_id'             => bp_displayed_user_id(),
    120             'hide_empty_groups'   => false,
    121             'hide_empty_fields'   => false,
    122             'fetch_fields'        => false,
    123             'fetch_field_data'    => false,
     118            'profile_group_id'       => false,
     119            'user_id'                => bp_displayed_user_id(),
     120            'hide_empty_groups'      => false,
     121            'hide_empty_fields'      => false,
     122            'fetch_fields'           => false,
     123            'fetch_field_data'       => false,
    124124            'fetch_visibility_level' => false,
    125             'exclude_groups'      => false,
    126             'exclude_fields'      => false
     125            'exclude_groups'         => false,
     126            'exclude_fields'         => false
    127127        );
    128128
     
    176176            return $groups;
    177177
    178         if ( ! empty( $fetch_field_data ) && ! empty( $user_id ) ) {
     178        if ( ! empty( $fetch_field_data ) ) {
    179179
    180180            // Fetch the field data for the user.
     
    185185            $field_ids_sql = implode( ',', (array) $field_ids );
    186186
    187             if ( !empty( $field_ids ) )
     187            if ( ! empty( $field_ids ) && ! empty( $user_id ) ) {
    188188                $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) AND user_id = %d", $user_id ) );
     189            }
    189190
    190191            // Remove data-less fields, if necessary
     
    233234            }
    234235
    235             if ( $fetch_visibility_level ) {
     236            if ( !empty( $fetch_visibility_level ) ) {
    236237                $fields = self::fetch_visibility_level( $user_id, $fields );
    237238            }
     
    294295     * @return array $fields The database results, with field_visibility added
    295296     */
    296     function fetch_visibility_level( $user_id, $fields ) {
     297    function fetch_visibility_level( $user_id = 0, $fields = array() ) {
    297298
    298299        // Get the user's visibility level preferences
     
    302303        $admin_set_levels  = self::fetch_default_visibility_levels();
    303304
    304         foreach( (array)$fields as $key => $field ) {
     305        foreach( (array) $fields as $key => $field ) {
     306
    305307            // Does the admin allow this field to be customized?
    306308            $allow_custom = empty( $admin_set_levels[$field->id]['allow_custom'] ) || 'allowed' == $admin_set_levels[$field->id]['allow_custom'];
     
    309311            if ( $allow_custom && isset( $visibility_levels[$field->id] ) ) {
    310312                $field_visibility = $visibility_levels[$field->id];
     313
     314            // If no admin-set default is saved, fall back on a global default
    311315            } else {
    312                 // If no admin-set default is saved, fall back on a global default
    313316                $field_visibility = !empty( $admin_set_levels[$field->id]['default'] ) ? $admin_set_levels[$field->id]['default'] : apply_filters( 'bp_xprofile_default_visibility_level', 'public' );
    314317            }
Note: See TracChangeset for help on using the changeset viewer.