Skip to:
Content

BuddyPress.org

Ticket #6751: 6751.01.patch

File 6751.01.patch, 1.6 KB (added by dcavins, 9 years ago)

Differentiate when the user has selected none of the options versus when the user has not yet saved a value for this field.

  • 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..efcfdf3 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                // Differentiate null values.
     109                // If the user has specifically chosen none of the options, $option_value will be an empty array.
     110                // If the user has no saved value for this field, $option_value will be an empty string.
     111                $user_has_saved_value = true;
     112                if ( empty( $option_values ) && ! is_array( $option_values ) ) {
     113                        $user_has_saved_value = false;
     114                }
    107115                $option_values = ( $option_values ) ? (array) $option_values : array();
    108116
    109117                $html = '';
    class BP_XProfile_Field_Type_Checkbox extends BP_XProfile_Field_Type { 
    134142
    135143                        // If the user has not yet supplied a value for this field, check to
    136144                        // see whether there is a default value available.
    137                         if ( empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
     145                        if ( ! $user_has_saved_value && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
    138146                                $selected = ' checked="checked"';
    139147                        }
    140148