Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/03/2010 06:53:59 AM (16 years ago)
Author:
johnjamesjacoby
Message:

Allow xprofile field groups to be reordered. Also swept through xprofile files and cleaned up code formatting.

File:
1 edited

Legend:

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

    r2654 r2798  
    6161                        return false;
    6262
    63                 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id );
    64 
    65                 if ( !$wpdb->query($sql) ) {
    66                         return false;
    67                 } else {
    68                         // Now the group is deleted, remove the group's fields.
    69                         if ( BP_XProfile_Field::delete_for_group($this->id) ) {
    70                                 // Now delete all the profile data for the groups fields
    71                                 for ( $i = 0; $i < count($this->fields); $i++ ) {
    72                                         BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id);
    73                                 }
     63                /* Delete field group */
     64                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ) ) ) {
     65                        return false;
     66                } else {
     67                        /* Remove the group's fields. */
     68                        if ( BP_XProfile_Field::delete_for_group( $this->id ) ) {
     69                                /* Remove profile data for the groups fields */
     70                                foreach ( $this->fields as $field )
     71                                        BP_XProfile_ProfileData::delete_for_field( $field->id );
     72
    7473                        }
    7574
     
    9897
    9998                if ( $hide_empty_groups )
    100                         $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.id ASC" ) );
     99                        $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" ) );
    101100                else
    102                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$group_id_sql} ORDER BY g.id ASC" ) );
     101                        $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" ) );
    103102
    104103                if ( !$fetch_fields )
     
    154153                global $message;
    155154
    156                 // Validate Form
     155                /* Validate Form */
    157156                if ( empty( $_POST['group_name'] ) ) {
    158157                        $message = __('Please make sure you give the group a name.', 'buddypress');
     
    163162        }
    164163
    165         // ADMIN AREA HTML. TODO: Get this out of here.
     164        function update_position( $field_group_id, $position ) {
     165                global $wpdb, $bp;
     166
     167                if ( !is_numeric( $position ) )
     168                        return false;
     169
     170                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) );
     171        }
     172
     173        /* ADMIN AREA HTML. TODO: Get this out of here. */
    166174
    167175        function render_admin_form() {
     
    175183                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;
    176184                }
    177         ?>
     185?>
    178186                <div class="wrap">
    179187
     
    206214                </div>
    207215
    208                 <?php
     216<?php
    209217        }
    210218}
     
    230238
    231239        function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {
    232                 if ( $id ) {
     240                if ( $id )
    233241                        $this->populate( $id, $user_id, $get_data );
    234                 }
    235242        }
    236243
     
    238245                global $wpdb, $userdata, $bp;
    239246
    240                 if ( is_null($user_id) ) {
     247                if ( is_null( $user_id ) )
    241248                        $user_id = $userdata->ID;
    242                 }
    243249
    244250                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id );
    245251
    246                 if ( $field = $wpdb->get_row($sql) ) {
     252                if ( $field = $wpdb->get_row( $sql ) ) {
    247253                        $this->id = $field->id;
    248254                        $this->group_id = $field->group_id;
     
    258264                        $this->is_default_option = $field->is_default_option;
    259265
    260                         if ( $get_data ) {
     266                        if ( $get_data )
    261267                                $this->data = $this->get_field_data($user_id);
    262                         }
     268
    263269                }
    264270        }
     
    268274
    269275                if ( !$this->id ||
    270                         // Prevent deletion by url when can_delete is false.
     276                        /* Prevent deletion by url when can_delete is false. */
    271277                        !$this->can_delete ||
    272                         // Prevent deletion of option 1 since this invalidates fields with options.
     278                        /* Prevent deletion of option 1 since this invalidates fields with options. */
    273279                        ( $this->parent_id && $this->option_order == 1 ) )
    274280                        return false;
     
    277283                        return false;
    278284
    279                 // delete the data in the DB for this field
    280                 BP_XProfile_ProfileData::delete_for_field($this->id);
     285                /* delete the data in the DB for this field */
     286                BP_XProfile_ProfileData::delete_for_field( $this->id );
    281287
    282288                return true;
     
    300306
    301307                if ( $this->id != null )
    302                         $sql = $wpdb->prepare("UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id);
     308                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id);
    303309                else
    304                         $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, 0, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order );
    305 
    306                 // Check for null so field options can be changed without changing any other part of the field.
    307                 // The described situation will return 0 here.
    308                 if ( $wpdb->query($sql) !== null ) {
     310                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, 0, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order );
     311
     312                /*
     313                 * Check for null so field options can be changed without changing any other part of the field.
     314                 * The described situation will return 0 here.
     315                 */
     316                if ( $wpdb->query( $sql ) !== null ) {
    309317
    310318                        if ( $this->id )
     
    313321                                $field_id = $wpdb->insert_id;
    314322
    315                         // Only do this if we are editing an existing field
     323                        /* Only do this if we are editing an existing field */
    316324                        if ( $this->id != null ) {
    317                                 // Remove any radio or dropdown options for this
    318                                 // field. They will be re-added if needed.
    319                                 // This stops orphan options if the user changes a
    320                                 // field from a radio button field to a text box.
     325                                /*
     326                                 * Remove any radio or dropdown options for this
     327                                 * field. They will be re-added if needed.
     328                                 * This stops orphan options if the user changes a
     329                                 * field from a radio button field to a text box.
     330                                 */
    321331                                $this->delete_children();
    322332                        }
    323333
    324                         // Check to see if this is a field with child options.
    325                         // We need to add the options to the db, if it is.
     334                        /*
     335                         * Check to see if this is a field with child options.
     336                         * We need to add the options to the db, if it is.
     337                         */
    326338                        if ( 'radio' == $this->type || 'selectbox' == $this->type || 'checkbox' == $this->type || 'multiselectbox' == $this->type ) {
    327                                 if ( $this->id ) {
     339                                if ( $this->id )
    328340                                        $parent_id = $this->id;
    329                                 } else {
     341                                else
    330342                                        $parent_id = $wpdb->insert_id;
    331                                 }
    332343
    333344                                if ( 'radio' == $this->type ) {
    334 
    335345                                        $options = $_POST['radio_option'];
    336346                                        $defaults = $_POST['isDefault_radio_option'];
    337347
    338348                                } else if ( 'selectbox' == $this->type ) {
    339 
    340349                                        $options = $_POST['selectbox_option'];
    341350                                        $defaults = $_POST['isDefault_selectbox_option'];
    342351
    343352                                } else if ( 'multiselectbox' == $this->type ) {
    344 
    345353                                        $options = $_POST['multiselectbox_option'];
    346354                                        $defaults = $_POST['isDefault_multiselectbox_option'];
    347355
    348356                                } else if ( 'checkbox' == $this->type ) {
    349 
    350357                                        $options = $_POST['checkbox_option'];
    351358                                        $defaults = $_POST['isDefault_checkbox_option'];
     
    358365                                                $is_default = 0;
    359366
    360                                                 if ( is_array($defaults) ) {
    361                                                         if ( isset($defaults[$option_key]) )
     367                                                if ( is_array( $defaults ) ) {
     368                                                        if ( isset( $defaults[$option_key] ) )
    362369                                                                $is_default = 1;
    363370                                                } else {
     
    367374
    368375                                                if ( '' != $option_value ) {
    369                                                         if ( !$wpdb->query( $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) )
     376                                                        if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) )
    370377                                                                return false;
    371378                                                }
     
    387394        }
    388395
    389         function get_field_data($user_id) {
    390                 return new BP_XProfile_ProfileData($this->id, $user_id);
    391         }
    392 
    393          function get_children($for_editing = false) {
    394                 global $wpdb, $bp;
    395 
    396                 // This is done here so we don't have problems with sql injection
    397                 if ( 'asc' == $this->order_by && !$for_editing ) {
     396        function get_field_data( $user_id ) {
     397                return new BP_XProfile_ProfileData( $this->id, $user_id );
     398        }
     399
     400        function get_children( $for_editing = false ) {
     401                global $wpdb, $bp;
     402
     403                /* This is done here so we don't have problems with sql injection */
     404                if ( 'asc' == $this->order_by && !$for_editing )
    398405                        $sort_sql = 'ORDER BY name ASC';
    399                 } else if ( 'desc' == $this->order_by && !$for_editing ) {
     406                else if ( 'desc' == $this->order_by && !$for_editing )
    400407                        $sort_sql = 'ORDER BY name DESC';
    401                 } else {
     408                else
    402409                        $sort_sql = 'ORDER BY option_order ASC';
    403                 }
    404 
    405                 //This eliminates a problem with getting all fields when there is no id for the object
    406                 if ( !$this->id ) {
     410
     411                /* This eliminates a problem with getting all fields when there is no id for the object */
     412                if ( !$this->id )
    407413                        $parent_id = -1;
    408                 } else {
     414                else
    409415                        $parent_id = $this->id;
    410                 }
    411416
    412417                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id );
     
    426431        }
    427432
    428         // Static Functions
     433        /* Static Functions */
    429434
    430435        function get_type( $field_id ) {
     
    434439                        $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id );
    435440
    436                         if ( !$field_type = $wpdb->get_var($sql) )
     441                        if ( !$field_type = $wpdb->get_var( $sql ) )
    437442                                return false;
    438443
     
    449454                        $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
    450455
    451                         if ( $wpdb->get_var($sql) === false ) {
     456                        if ( $wpdb->get_var($sql) === false )
    452457                                return false;
    453                         }
    454458
    455459                        return true;
     
    477481        }
    478482
    479         // ADMIN AREA HTML. TODO: Get this out of here.
    480 
     483        /* ADMIN AREA HTML. TODO: Get this out of here. */
     484
     485        /* This function populates the items for radio buttons checkboxes and drop down boxes */
    481486        function render_admin_form_children() {
    482                 //This function populates the items for radio buttons checkboxes and drop down boxes
    483487                $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' );
    484488
     
    486490                        $default_name = '';
    487491
    488                         if ( 'multiselectbox' == $type || 'checkbox' == $type ) {
     492                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    489493                                $default_input = 'checkbox';
    490                         } else {
     494                        else
    491495                                $default_input = 'radio';
    492                         }
    493                 ?>
     496?>
    494497                        <div id="<?php echo $type ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;">
    495498                                <h4><?php _e('Please enter options for this Field:', 'buddypress') ?></h4>
    496499                                <p><?php _e( 'Order By:', 'buddypress' ) ?>
    497 
    498500                                        <select name="sort_order_<?php echo $type ?>" id="sort_order_<?php echo $type ?>" >
    499501                                                <option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ) ?></option>
     
    501503                                                <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ) ?></option>
    502504                                        </select>
    503 
    504                                 <?php
     505<?php
    505506                                if ( !$options = $this->get_children(true) ) {
    506507                                        $i = 1;
     
    520521                                }
    521522
    522                                 if ( !empty($options) ) {
     523                                if ( !empty( $options ) ) {
    523524                                        for ( $i = 0; $i < count($options); $i++ ) {
    524525                                                $j = $i + 1;
     
    526527                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
    527528                                                        $default_name = '[' . $j . ']';
    528                                         ?>
     529                                                ?>
    529530                                                <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>:
    530531                                                   <input type="text" name="<?php echo $type ?>_option[<?php echo $j ?>]" id="<?php echo $type ?>_option<?php echo $j ?>" value="<?php echo attribute_escape( $options[$i]->name ) ?>" />
     
    533534                                                                $options[$i]->id != -1 ) : ?><a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id ?>">[x]</a><?php endif ?></p>
    534535                                                </p>
    535                                         <?php } // end for ?>
     536                                        <?php } /* end for */ ?>
    536537                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="<?php echo $j + 1 ?>" />
    537538
     
    546547                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" />
    547548
    548                                 <?php } // end if ?>
     549                                <?php } /* end if */ ?>
    549550                                <div id="<?php echo $type ?>_more"></div>
    550551                                <p><a href="javascript:add_option('<?php echo $type ?>')"><?php _e('Add Another Option', 'buddypress') ?></a></p>
     
    556557        function render_admin_form( $message = '' ) {
    557558                if ( !$this->id ) {
    558                         $title = __('Add Field', 'buddypress');
    559                         $action = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
     559                        $title                          = __('Add Field', 'buddypress');
     560                        $action                         = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
    560561
    561562                        $this->name                     = $_POST['title'];
     
    565566                        $this->order_by         = $_POST["sort_order_{$this->type}"];
    566567                } else {
    567                         $title = __('Edit Field', 'buddypress');
    568                         $action = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;
     568                        $title                          = __('Edit Field', 'buddypress');
     569                        $action                         = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;
    569570                }
    570571        ?>
     
    623624
    624625                                <p class="submit">
    625                                                 &nbsp;<input type="submit" value="<?php _e("Save", 'buddypress') ?> &rarr;" name="saveField" id="saveField" style="font-weight: bold" />
    626                                                 <?php _e('or', 'buddypress') ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a>
     626                                        &nbsp;<input type="submit" value="<?php _e("Save", 'buddypress') ?> &rarr;" name="saveField" id="saveField" style="font-weight: bold" />
     627                                        <?php _e('or', 'buddypress') ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a>
    627628                                </p>
    628629
     630                        </div>
     631
    629632                        <div class="clear"></div>
    630633
    631                         <?php if ( function_exists('wp_nonce_field') )
    632                                 wp_nonce_field('xprofile_delete_option');
    633                         ?>
     634                        <?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'xprofile_delete_option' ); ?>
    634635
    635636                </form>
    636637        </div>
    637638
    638         <?php
     639<?php
    639640        }
    640641
     
    642643                global $message;
    643644
    644                 // Validate Form
     645                /* Validate Form */
    645646                if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) {
    646                         $message = __('Please make sure you fill out all required fields.', 'buddypress');
     647                        $message = __( 'Please make sure you fill out all required fields.', 'buddypress' );
    647648                        return false;
    648649                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'radio' && empty($_POST['radio_option'][1]) ) {
    649                         $message = __('Radio button field types require at least one option. Please add options below.', 'buddypress');
     650                        $message = __( 'Radio button field types require at least one option. Please add options below.', 'buddypress' );
    650651                        return false;
    651652                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'selectbox' && empty($_POST['selectbox_option'][1]) ) {
    652                         $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');
     653                        $message = __( 'Select box field types require at least one option. Please add options below.', 'buddypress' );
    653654                        return false;
    654655                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'multiselectbox' && empty($_POST['multiselectbox_option'][1]) ) {
    655                         $message = __('Select box field types require at least one option. Please add options below.', 'buddypress');
     656                        $message = __( 'Select box field types require at least one option. Please add options below.', 'buddypress' );
    656657                        return false;
    657658                } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'checkbox' && empty($_POST['checkbox_option'][1]) ) {
    658                         $message = __('Checkbox field types require at least one option. Please add options below.', 'buddypress');
     659                        $message = __( 'Checkbox field types require at least one option. Please add options below.', 'buddypress' );
    659660                        return false;
    660661                } else {
     
    673674
    674675        function bp_xprofile_profiledata( $field_id = null, $user_id = null ) {
    675                 if ( $field_id ) {
     676                if ( $field_id )
    676677                        $this->populate( $field_id, $user_id );
    677                 }
    678678        }
    679679
     
    683683                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id );
    684684
    685                 if ( $profiledata = $wpdb->get_row($sql) ) {
    686 
     685                if ( $profiledata = $wpdb->get_row( $sql ) ) {
    687686                        $this->id = $profiledata->id;
    688687                        $this->user_id = $profiledata->user_id;
     
    696695                global $wpdb, $bp;
    697696
    698                 // check to see if there is data already for the user.
     697                /* Check to see if there is data already for the user. */
    699698                $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id );
    700699
    701                 if ( !$wpdb->get_row($sql) )
     700                if ( !$wpdb->get_row( $sql ) )
    702701                        return false;
    703702
     
    708707                global $wpdb, $bp;
    709708
    710                 // check to see if this data is actually for a valid field.
    711                 $sql = $wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id );
    712 
    713                 if ( !$wpdb->get_row($sql) )
     709                /* check to see if this data is actually for a valid field. */
     710                $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id );
     711
     712                if ( !$wpdb->get_row( $sql ) )
    714713                        return false;
    715714
     
    728727
    729728                if ( $this->is_valid_field() ) {
    730                         if ( $this->exists() && !empty( $this->value ) && strlen( trim( $this->value ) ) ) {
     729                        if ( $this->exists() && !empty( $this->value ) && strlen( trim( $this->value ) ) )
    731730                                $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_data} SET value = %s, last_updated = %s WHERE user_id = %d AND field_id = %d", $this->value, $this->last_updated, $this->user_id, $this->field_id ) );
    732                         } else if ( $this->exists() && empty( $this->value ) ) {
    733                                 // Data removed, delete the entry.
     731
     732                        /* Data removed, delete the entry. */
     733                        else if ( $this->exists() && empty( $this->value ) )
    734734                                $result = $this->delete();
    735                         } else {
     735
     736                        else
    736737                                $result = $wpdb->query( $wpdb->prepare("INSERT INTO {$bp->profile->table_name_data} (user_id, field_id, value, last_updated) VALUES (%d, %d, %s, %s)", $this->user_id, $this->field_id, $this->value, $this->last_updated ) );
    737                         }
    738738
    739739                        if ( !$result )
     
    800800                        $user_ids = implode( ',', (array)$user_ids );
    801801                        $data = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$user_ids})", $field_id ) );
    802                 } else
     802                } else {
    803803                        $data = $wpdb->get_var( $wpdb->prepare( "SELECT value FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_ids ) );
     804                }
    804805
    805806                return $data;
     
    835836                $sql = $wpdb->prepare( "SELECT d.value, f.name FROM {$bp->profile->table_name_data} d, {$bp->profile->table_name_fields} f WHERE d.field_id = f.id AND d.user_id = %d AND f.parent_id = 0 $field_sql", $user_id );
    836837
    837                 if ( !$values = $wpdb->get_results($sql) )
     838                if ( !$values = $wpdb->get_results( $sql ) )
    838839                        return false;
    839840
    840841                $new_values = array();
    841842
    842                 if ( is_array($fields) ) {
    843                         for ( $i = 0; $i < count($values); $i++ ) {
    844                                 for ( $j = 0; $j < count($fields); $j++ ) {
     843                if ( is_array( $fields ) ) {
     844                        for ( $i = 0; $i < count( $values ); $i++ ) {
     845                                for ( $j = 0; $j < count( $fields ); $j++ ) {
    845846                                        if ( $values[$i]->name == $fields[$j] ) {
    846847                                                $new_values[$fields[$j]] = $values[$i]->value;
     
    900901        }
    901902}
     903
    902904?>
Note: See TracChangeset for help on using the changeset viewer.