Skip to:
Content

BuddyPress.org

Ticket #6751: 6751.02.patch

File 6751.02.patch, 1.8 KB (added by dcavins, 9 years ago)
  • src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox.php src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox.php
    index 736c66c..fc15b2e 100644
    class BP_XProfile_Field_Type_Checkbox extends BP_XProfile_Field_Type { 
    104104        public function edit_field_options_html( array $args = array() ) {
    105105                $options       = $this->field_obj->get_children();
    106106                $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ) );
     107
     108                /*
     109                 * Determine whether to pre-select the default option.
     110                 *
     111                 * If there's no saved value, take the following into account:
     112                 * If the user has never saved a value for this field,
     113                 * $option_values will be an empty string, and we should pre-select the default option.
     114                 * If the user has specifically chosen none of the options,
     115                 * $option_values will be an empty array, and we should respect that value.
     116                 */
     117                $select_default_option = false;
     118                if ( empty( $option_values ) && ! is_array( $option_values ) ) {
     119                        $select_default_option = true;
     120                }
     121
    107122                $option_values = ( $option_values ) ? (array) $option_values : array();
    108123
    109124                $html = '';
    class BP_XProfile_Field_Type_Checkbox extends BP_XProfile_Field_Type { 
    134149
    135150                        // If the user has not yet supplied a value for this field, check to
    136151                        // see whether there is a default value available.
    137                         if ( empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
     152                        if ( empty( $selected ) && $select_default_option && ! empty( $options[$k]->is_default_option ) ) {
    138153                                $selected = ' checked="checked"';
    139154                        }
    140155