[buddypress-trac] [BuddyPress Trac] #5731: text/number profile fields not rendered if value == 0

buddypress-trac noreply at wordpress.org
Fri Jun 27 20:29:38 UTC 2014

#5731: text/number profile fields not rendered if value == 0
 Reporter:  DJPaul        |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  2.1
Component:  XProfile      |     Version:  1.0
 Severity:  normal        |  Resolution:
 Keywords:                |
Changes (by DJPaul):

 * version:   => 1.0


 While it's not a new issue, I'm pretty impressed that we've not seen this
 issue until now. I bet it goes back to xprofile's original implementation.
 The tl;dr is that we're being a bit lazy validating if variables have no
 values by relying on `empty()`.

 From php.net:

 The following things are considered to be empty:

 "" (an empty string)
 0 (0 as an integer)
 0.0 (0 as a float)
 "0" (0 as a string)
 array() (an empty array)
 $var; (a variable declared, but without a value)

 As a result, if an xprofile field's value is set to 0 or "0", we think the
 value is not set.

 I am unsure the best way to patch this, but see 5371.01.patch for one
 idea; `empty()` does helpfully check for a lot of cases of values that
 xprofile would want to see as empty, so I thought that maybe adding an IF
 to check for 0 or "0" would result in less code change than if we did
 something like the following, even though it looks kinda janky: `if (
 $value && $value !== false && $value !== array() && ... )`

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5731#comment:4>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac

More information about the buddypress-trac mailing list