Ticket #3074: 3074.03.patch
File 3074.03.patch, 5.5 KB (added by , 13 years ago) |
---|
-
bp-xprofile/bp-xprofile-classes.php
Class BP_XProfile_Group { 113 113 'profile_group_id' => false, 114 114 'user_id' => $bp->displayed_user->id, 115 115 'hide_empty_groups' => false, 116 'hide_empty_fields' => false, 116 117 'fetch_fields' => false, 117 118 'fetch_field_data' => false, 118 119 'exclude_groups' => false, … … Class BP_XProfile_Group { 161 162 foreach( (array)$fields as $field ) 162 163 $field_ids[] = $field->id; 163 164 164 $field_ids = implode( ',', (array) $field_ids );165 $field_ids_sql = implode( ',', (array) $field_ids ); 165 166 166 167 if ( !empty( $field_ids ) ) 167 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids} ) AND user_id = %d", $user_id ) ); 168 168 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) AND user_id = %d", $user_id ) ); 169 170 // Remove data-less fields, if necessary 171 if ( $hide_empty_fields ) { 172 // Loop through the results and find the fields that have data. 173 foreach( (array)$field_data as $data ) { 174 if ( false !== $key = array_search( $data->field_id, $field_ids ) ) { 175 // Fields that have data get removed from the list 176 unset( $field_ids[$key] ); 177 } 178 } 179 180 // The remaining members of $field_ids are empty. Remove them. 181 foreach( $fields as $field_key => $field ) { 182 if ( in_array( $field->id, $field_ids ) ) { 183 unset( $fields[$field_key] ); 184 } 185 } 186 187 // Reset the indexes 188 $fields = array_values( $fields ); 189 } 190 169 191 if ( !empty( $field_data ) ) { 170 192 foreach( (array)$fields as $field_key => $field ) { 171 193 foreach( (array)$field_data as $data ) { … … Class BP_XProfile_Group { 182 204 if ( $group->id == $field->group_id ) 183 205 $groups[$group_key]->fields[] = $field; 184 206 } 207 208 if ( empty( $group->fields ) ) { 209 unset( $groups[$group_key] ); 210 } 211 212 // Reset indexes 213 $groups = array_values( $groups ); 185 214 } 186 215 187 216 return $groups; -
bp-xprofile/bp-xprofile-template.php
Class BP_XProfile_Data_Template { 20 20 var $in_the_loop; 21 21 var $user_id; 22 22 23 function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false ) {24 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );23 function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) { 24 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields ); 25 25 } 26 26 27 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false ) {27 function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) { 28 28 $this->groups = BP_XProfile_Group::get( array( 29 29 'profile_group_id' => $profile_group_id, 30 30 'user_id' => $user_id, 31 31 'hide_empty_groups' => $hide_empty_groups, 32 'hide_empty_fields' => $hide_empty_fields, 32 33 'fetch_fields' => $fetch_fields, 33 34 'fetch_field_data' => $fetch_field_data, 34 35 'exclude_groups' => $exclude_groups, … … function xprofile_get_profile() { 152 153 function bp_has_profile( $args = '' ) { 153 154 global $bp, $profile_template; 154 155 156 // Only show empty fields on the Dashboard or the user profile edit screen 157 if ( bp_is_user_profile_edit() || is_admin() || is_network_admin() ) 158 $hide_empty_fields = false; 159 else 160 $hide_empty_fields = true; 161 155 162 $defaults = array( 156 163 'user_id' => $bp->displayed_user->id, 157 164 'profile_group_id' => false, 158 165 'hide_empty_groups' => true, 166 'hide_empty_fields' => $hide_empty_fields, 159 167 'fetch_fields' => true, 160 168 'fetch_field_data' => true, 161 169 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude … … function bp_has_profile( $args = '' ) { 165 173 $r = wp_parse_args( $args, $defaults ); 166 174 extract( $r, EXTR_SKIP ); 167 175 168 $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );176 $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields ); 169 177 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); 170 178 } 171 179 … … function bp_field_css_class( $class = false ) { 189 197 } 190 198 function bp_get_field_css_class( $class = false ) { 191 199 global $profile_template; 192 200 193 201 $css_classes = array(); 194 202 195 203 if ( $class )