[buddypress-trac] [BuddyPress] #5018: Update user meta field 'total_group_count' when user joins group

buddypress-trac noreply at wordpress.org
Tue May 28 14:00:01 UTC 2013

#5018: Update user meta field 'total_group_count' when user joins group
 Reporter:  mukkundthanki  |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  1.8
Component:  Groups         |     Version:  1.7
 Severity:  normal         |  Resolution:
 Keywords:                 |

Comment (by mukkundthanki):

 ya, we have this function 'groups_total_groups_for_user' which count
 groups for user we can make use of it to update it. and I think while we
 decrease this count simple check for greater than zero would work...

 bp_update_user_meta( $user_id, 'total_group_count', (int)
 groups_total_groups_for_user( $user_id ) + 1 );

 and for leave group

 if( (int) groups_total_groups_for_user( $user_id ) > 0 )
         bp_update_user_meta( $user_id, 'total_group_count', (int) (int)
 groups_total_groups_for_user( $user_id ) - 1 );

 if user's group count is already zero then we don't decrease it. It seems
 little funny but I think it could be happen by mistake, because we don't
 check for user membership in this function so, its necessary to avoid
 minus count.

 I have not tested it though, but it seems working.

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5018#comment:2>
BuddyPress <http://buddypress.org/>

More information about the buddypress-trac mailing list