Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/09/2010 12:59:25 PM (16 years ago)
Author:
boonebgorges
Message:

Adds several exclude parameters to bp_has_profile(). Fixes #2655

File:
1 edited

Legend:

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

    r3369 r3381  
    8080        /** Static Functions **/
    8181
     82        /**
     83         * get()
     84         *
     85         * Populates the BP_XProfile_Group object with profile field groups, fields, and field data
     86         *
     87         * @package BuddyPress XProfile
     88         *
     89         * @global $wpdb WordPress DB access object.
     90         * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     91         *
     92         * @param array $args Takes an array of parameters:
     93         *              'profile_group_id' - Limit results to a single profile group
     94         *              'user_id' - Required if you want to load a specific user's data
     95         *              'hide_empty_groups' - Hide groups without any fields
     96         *              'fetch_fields' - Load each group's fields
     97         *              'fetch_field_data' - Load each field's data. Requires a user_id
     98         *              'exclude_groups' - Comma-separated list of groups to exclude
     99         *              'exclude_fields' - Comma-separated list of fields to exclude
     100         *
     101         * @return array $groups
     102         */
    82103        function get( $args = '' ) {
    83104                global $wpdb, $bp;
    84105
    85106                $defaults = array(
    86                         'profile_group_id' => false,
    87                         'user_id' => $bp->displayed_user->id,
     107                        'profile_group_id'      => false,
     108                        'user_id'                       => $bp->displayed_user->id,
    88109                        'hide_empty_groups' => false,
    89                         'fetch_fields' => false,
    90                         'fetch_field_data' => false
     110                        'fetch_fields'          => false,
     111                        'fetch_field_data'      => false,
     112                        'exclude_groups'        => false,
     113                        'exclude_fields'        => false
    91114                );
    92115
    … …  
    96119                $group_id_sql = '';
    97120                if ( $profile_group_id )
    98                         $group_id_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
     121                        $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
     122                else if ( $exclude_groups )
     123                        $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})");
    99124
    100125                if ( $hide_empty_groups )
    101                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$group_id_sql} ORDER BY g.group_order ASC" ) );
     126                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" ) );
    102127                else
    103                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$group_id_sql} ORDER BY g.group_order ASC" ) );
     128                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC" ) );
    104129
    105130                if ( !$fetch_fields )
    106131                        return $groups;
    107132
    108                 /* Get the group ids */
     133                // Get the group ids
    109134                foreach( (array)$groups as $group ) {
    110135                        $group_ids[] = $group->id;
    … …  
    116141                        return $groups;
    117142
    118                 /* Fetch the fields */
    119                 $fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, description, type, group_id, is_required FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 ORDER BY field_order" ) );
     143                if ( $exclude_fields )
     144                        $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" );
     145
     146                // Fetch the fields
     147                $fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, description, type, group_id, is_required FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 {$exclude_fields_sql} ORDER BY field_order" ) );
    120148
    121149                if ( empty( $fields ) )
    … …  
    123151
    124152                if ( $fetch_field_data ) {
    125                         /* Fetch the field data for the user. */
     153                        // Fetch the field data for the user.
    126154                        foreach( (array)$fields as $field )
    127155                                $field_ids[] = $field->id;
    … …  
    142170                }
    143171
    144                 /* Merge the field array back in with the group array */
     172                // Merge the field array back in with the group array
    145173                foreach( (array)$groups as $group_key => $group ) {
    146174                        foreach( (array)$fields as $field ) {
Note: See TracChangeset for help on using the changeset viewer.