Ticket #3233: xprofil-select-multiselect-field-patch.patch
File xprofil-select-multiselect-field-patch.patch, 2.6 KB (added by , 14 years ago) |
---|
-
bp-xprofile/bp-xprofile-template.php
407 407 $field = new BP_XProfile_Field( $field->id ); 408 408 409 409 $options = $field->get_children(); 410 410 411 411 // Setup some defaults 412 412 $html = ''; 413 413 $selected = ''; … … 417 417 case 'selectbox': case 'multiselectbox': 418 418 if ( 'multiselectbox' != $field->type ) 419 419 $html .= '<option value="">--------</option>'; 420 420 //find the values selected by user 421 $user_selected_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) ); 422 421 423 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 $option_values = (array) $user_selected_values; 424 425 425 // Check for updated posted values, but errors preventing them from being saved first time 426 foreach( $option_values as $i => $option_value ) { 427 if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) { 428 if ( !empty( $_POST['field_' . $field->id] ) ) 429 $option_values[$i] = $_POST['field_' . $field->id]; 430 } 431 } 432 426 433 427 $selected = ''; 434 428 435 429 // Run the allowed option name through the before_save 436 430 // filter, so we'll be sure to get a match 437 $ allowed_options= xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );431 $current_option = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); 438 432 439 433 // First, check to see whether the user-entered value 440 434 // matches 441 if ( in_array( $ allowed_options, (array)$option_values ) )435 if ( in_array( $current_option, $option_values ) ) 442 436 $selected = ' selected="selected"'; 443 437 444 438 // Then, if the user has not provided a value, check for 445 439 // defaults 446 if ( !is_array( $ original_option_values ) && empty( $option_values ) & $options[$k]->is_default_option )440 if ( !is_array( $user_selected_values ) && empty( $user_selected_values ) & $options[$k]->is_default_option ) 447 441 $selected = ' selected="selected"'; 448 442 449 443 $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k] );