Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/21/2015 02:27:49 PM (10 years ago)
Author:
djpaul
Message:

xprofile: fix broken selection of default values for checkboxes, select boxes, and multi-select boxes.

When we try to fetch a user's profile field value from the database, if it wasn't set, then we return an empty string.
A few profile field types were mishandling an empty string response from BP_XProfile_ProfileData::get_value_byid, and it was being mistakenly interpreted as a user selected value.

This change checks the return value from BP_XProfile_ProfileData::get_value_byid, and if it's empty, instead of always casting the value, sets the ongoing variable to an empty array instead.

Fixes #6134

File:
1 edited

Legend:

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

    r9486 r9521  
    102102    public function edit_field_options_html( array $args = array() ) {
    103103        $options       = $this->field_obj->get_children();
    104         $option_values = BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] );
    105         $option_values = (array) maybe_unserialize( $option_values );
     104        $option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ) );
     105        $option_values = ( $option_values ) ? (array) $option_values : array();
    106106
    107107        $html = '';
     
    133133            // If the user has not yet supplied a value for this field, check to
    134134            // see whether there is a default value available
    135             if ( ! is_array( $option_values ) && empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
     135            if ( empty( $option_values ) && empty( $selected ) && ! empty( $options[$k]->is_default_option ) ) {
    136136                $selected = ' checked="checked"';
    137137            }
Note: See TracChangeset for help on using the changeset viewer.