[buddypress-trac] [BuddyPress Trac] #6749: bp_get_group_avatar() needs extra error checking

buddypress-trac noreply at wordpress.org
Mon Nov 23 18:43:14 UTC 2015

#6749: bp_get_group_avatar() needs extra error checking
 Reporter:  slaFFik                   |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Under Consideration
Component:  Tools - Warnings/Notices  |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  2nd-opinion               |
Changes (by boonebgorges):

 * keywords:   => 2nd-opinion
 * milestone:  Awaiting Review => Under Consideration


 I agree that there should be a way to get a group avatar outside of a
 group loop.

 I'm not 100% sure that `bp_get_group_avatar()` is the way to do it. Our
 `-template.php` functions are pretty inconsistent throughout BuddyPress.
 In some places, these functions accept an argument so that they can be
 used outside of the loop, and in other places they do not. Many of the
 `bp-groups-template.php` functions, for example, accept a `$group` object.
 It's easy for us to add this functionality to `bp_get_group_avatar()`, but
 this might also be a good time to take a moment and see whether we'd like
 to take a step toward greater consistency here. What if, for example, we
 introduced a function like this:

 function bp_get_group_from_param( $group = false ) {
     global $groups_template;

     $group_obj = null;

     if ( $group instanceof BP_Groups_Group ) { // or is_object()
         $group_obj = $group;
     } elseif ( is_numeric( $group ) ) {
         $group_obj = groups_get_group( array( 'group_id' => $group ) );
         // maybe some error checking to make sure the group exists
     } elseif ( isset( $groups_template->group ) ) {
         $group_obj = $groups_template->group;

     return $group_obj;

 Then, within each template function:

 function bp_get_group_avatar( $group = false ) {
     if ( ! $group = bp_get_group_from_param( $group ) ) {
         return '';

     // Now we can assume $group is correct

 This way, devs have the option of passing a group object, passing a group
 ID, or passing nothing and having the group determined from the group loop

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

More information about the buddypress-trac mailing list