Skip to:
Content

BuddyPress.org

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#4102 closed defect (bug) (fixed)

Fallback logic in bp_get_the_profile_field_options() is broken

Reported by: boonebgorges Owned by: boonebgorges
Milestone: 1.5.6 Priority: normal
Severity: minor Version:
Component: Extended Profile Keywords:
Cc:

Description

In bp_get_the_profile_field_options(), there are some logic errors in the way that the existing user value(s) for the field are checked (for purposes of the selected or checked attribute):

  • When pulling up user's existing data, we run it through maybe_unserialize() (since it might not be an array), but we don't account later in the function for the fact that the value might not have been an array to begin with (ie, by running count() on it; see eg line 541 https://buddypress.trac.wordpress.org/browser/tags/1.5.5/bp-xprofile/bp-xprofile-template.php#L526). This results in PHP warnings in some cases, and in others it ends up in us iterating over each letter in a string.
  • Because of the above-mentioned problem, existing string values are not being matched properly against arrays. If your value for the field is a string 'Leonardo', and the $allowed_options are array( 'Leonardo', 'Donatello', 'Raphael', 'Michelangelo' ) as checkboxes, 'Leonardo' should be checked. It currently is not.
  • We do a check on a $value variable a few times in this function, but it's never defined.

Note that these problems are very much edge cases. They only really arise (in my experience, at least) when the admin has changed a plaintext field to a checkbox/multiselect/radio field. However, this is not that strange of a thing to do, and if we can handle it gracefully and without much work (which we can), we should.

Change History (2)

#1 @boonebgorges
9 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5948]) Fixes problems is bp_get_the_profile_field_options():

  • In 'checkbox' case, cast existing values as an array, to avoid misunderstandings with count() and in_array() later in the function
  • In 'checkbox' case, replace call to non-existent 'value' variable to something that makes sense in context
  • Clears up PHP warnings, and allows for better maintenance of existing values when switching between xprofile field types.

Fixes #4102

#2 @boonebgorges
9 years ago

(In [5949]) Fixes problems is bp_get_the_profile_field_options():

  • In 'checkbox' case, cast existing values as an array, to avoid misunderstandings with count() and in_array() later in the function
  • In 'checkbox' case, replace call to non-existent 'value' variable to something that makes sense in context
  • Clears up PHP warnings, and allows for better maintenance of existing values when switching between xprofile field types.

Fixes #4102

Note: See TracTickets for help on using tickets.