Skip to:
Content

BuddyPress.org

Changeset 4431


Ignore:
Timestamp:
05/28/2011 06:01:48 PM (14 years ago)
Author:
djpaul
Message:

Don't do multiple queries when editing xprofile select/radio/checkboxes. Fixes #3233, props sbrajesh

File:
1 edited

Legend:

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

    r4372 r4431  
    419419                    $html .= '<option value="">--------</option>';
    420420
    421                 for ( $k = 0; $k < count($options); $k++ ) {
    422                     $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $options[$k]->parent_id ) );
    423                     $option_values = (array) $original_option_values;
    424 
     421                $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
     422                $option_values = (array) $original_option_values;
     423
     424                for ( $k = 0; $k < count( $options ); $k++ ) {
    425425                    // Check for updated posted values, but errors preventing them from being saved first time
    426426                    foreach( $option_values as $i => $option_value ) {
     
    432432
    433433                    $selected = '';
    434                    
     434
    435435                    // Run the allowed option name through the before_save
    436436                    // filter, so we'll be sure to get a match
    437437                    $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    438                    
     438
    439439                    // First, check to see whether the user-entered value
    440440                    // matches
     
    453453            case 'radio':
    454454                $html .= '<div id="field_' . $field->id . '">';
    455 
    456                 for ( $k = 0; $k < count($options); $k++ ) {
    457                     $option_value = BP_XProfile_ProfileData::get_value_byid($options[$k]->parent_id);
    458 
     455                $option_value = BP_XProfile_ProfileData::get_value_byid( $field->id );
     456
     457                for ( $k = 0; $k < count( $options ); $k++ ) {
    459458                    // Check for updated posted values, but errors preventing them from being saved first time
    460459                    if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
     
    462461                            $option_value = $_POST['field_' . $field->id];
    463462                    }
    464                    
     463
    465464                    // Run the allowed option name through the before_save
    466465                    // filter, so we'll be sure to get a match
    467466                    $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    468                    
    469                     $selected = ''; 
     467
     468                    $selected = '';
    470469                    if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && $options[$k]->is_default_option ) )
    471470                        $selected = ' checked="checked"';
     
    478477
    479478            case 'checkbox':
    480                 $option_values = BP_XProfile_ProfileData::get_value_byid($options[0]->parent_id);
     479                $option_values = BP_XProfile_ProfileData::get_value_byid( $field->id );
     480                $option_values = maybe_unserialize( $option_values );
    481481
    482482                // Check for updated posted values, but errors preventing them from being saved first time
     
    486486                }
    487487
    488                 $option_values = maybe_unserialize($option_values);
    489                
    490                 for ( $k = 0; $k < count($options); $k++ ) {
     488                for ( $k = 0; $k < count( $options ); $k++ ) {
    491489                    $selected = '';
    492                    
     490
    493491                    // First, check to see whether the user's saved values
    494492                    // match the option
    495                     for ( $j = 0; $j < count($option_values); $j++ ) {
    496                        
     493                    for ( $j = 0; $j < count( $option_values ); $j++ ) {
     494
    497495                        // Run the allowed option name through the
    498496                        // before_save filter, so we'll be sure to get a
    499497                        // match
    500498                        $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    501                        
     499
    502500                        if ( $option_values[$j] == $allowed_options || @in_array( $allowed_options, $value ) ) {
    503501                            $selected = ' checked="checked"';
     
    505503                        }
    506504                    }
    507                    
     505
    508506                    // If the user has not yet supplied a value for this field,
    509507                    // check to see whether there is a default value available
Note: See TracChangeset for help on using the changeset viewer.