Skip to:
Content

BuddyPress.org

Changeset 9521


Ignore:
Timestamp:
02/21/2015 02:27:49 PM (9 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

Location:
trunk/src/bp-xprofile/classes
Files:
3 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            }
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-multiselectbox.php

    r9486 r9521  
    117117        }
    118118
    119         $option_values = (array) $original_option_values;
     119        $option_values = ( $original_option_values ) ? (array) $original_option_values : array();
    120120        for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
    121121            $selected = '';
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-selectbox.php

    r9486 r9521  
    105105        }
    106106
    107         $option_values = (array) $original_option_values;
     107        $option_values = ( $original_option_values ) ? (array) $original_option_values : array();
    108108        for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
    109109            $selected = '';
Note: See TracChangeset for help on using the changeset viewer.