Skip to:
Content

BuddyPress.org

Changeset 10561


Ignore:
Timestamp:
02/08/2016 05:09:08 PM (10 years ago)
Author:
dcavins
Message:

Profile checkboxes: Allow users to select none.

Previously, the default option was pre-selected
whether the user had never completed the
checkbox field or the user had selected none.
This changeset differentiates the null values and
respects a user's none-of-the-above choice.

Fixes #6751.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox.php

    r10417 r10561  
    106106                $options       = $this->field_obj->get_children();
    107107                $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ) );
     108
     109                /*
     110                 * Determine whether to pre-select the default option.
     111                 *
     112                 * If there's no saved value, take the following into account:
     113                 * If the user has never saved a value for this field,
     114                 * $option_values will be an empty string, and we should pre-select the default option.
     115                 * If the user has specifically chosen none of the options,
     116                 * $option_values will be an empty array, and we should respect that value.
     117                 */
     118                $select_default_option = false;
     119                if ( empty( $option_values ) && ! is_array( $option_values ) ) {
     120                        $select_default_option = true;
     121                }
     122
    108123                $option_values = ( $option_values ) ? (array) $option_values : array();
    109124
     
    136151                        // If the user has not yet supplied a value for this field, check to
    137152                        // see whether there is a default value available.
    138                         if ( empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
     153                        if ( empty( $selected ) && $select_default_option && ! empty( $options[$k]->is_default_option ) ) {
    139154                                $selected = ' checked="checked"';
    140155                        }
Note: See TracChangeset for help on using the changeset viewer.