[buddypress-trac] [BuddyPress Trac] #6734: `groups_get_groups()` doesn't distinguish between `0` and falsey values for `user_id`

buddypress-trac noreply at wordpress.org
Sat Nov 14 20:42:00 UTC 2015

#6734: `groups_get_groups()` doesn't distinguish between `0` and falsey values for
 Reporter:               |      Owner:
  boonebgorges           |     Status:  new
     Type:  defect       |  Milestone:  Awaiting Review
  (bug)                  |    Version:
 Priority:  normal       |   Keywords:  2nd-opinion needs-patch needs-unit-
Component:  Component -  |  tests
  Groups                 |
 Severity:  normal       |
 The default value for `user_id` in `groups_get_groups()` is `false`,
 which, as expected, means to ignore group memberships when fetching
 groups. But the way this is implemented in `BP_Groups_Group::get()` is
 with `! empty( $user_id )` checks. This means that passing `user_id=0`
 returns the same results. I would expect that `user_id=0` would always
 return an empty array - the groups that user 0 is a member of. This would
 be useful in the following sorts of cases:

 $groups_of_user = groups_get_groups( array
     'user_id' => bp_loggedin_user_id(),
 ) );

 As things stand, it's necessary to do different logic `if ( !
 is_user_logged_in() )`. (I found this out the hard way, because of some
 ugly access-related issues in a plugin I'm building.)

 Do people agree with me that `0` ought to mean something different than
 `false` or `null` in this context? What kinds of backward compatibility
 concerns should we expect? (Especially in `BP_Groups_Group::get()`, which
 has the default `user_id` of `0`.)

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6734>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac

More information about the buddypress-trac mailing list