[buddypress-trac] [BuddyPress Trac] #6597: Targeting the 'groups_leave_group' can be difficult
buddypress-trac
noreply at wordpress.org
Fri Aug 21 18:50:51 UTC 2015
#6597: Targeting the 'groups_leave_group' can be difficult
--------------------------------+-----------------------------
Reporter: thebrandonallen | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Component - Groups | Version: 2.3.0
Severity: normal | Keywords: dev-feedback
--------------------------------+-----------------------------
While working on #BB2488, I discovered that the `groups_leave_group`
action can be difficult to target. Prior to 2.3, `groups_leave_group()`
removed a member by "uninviting" them. Since 2.3, this is now done by
`groups_remove_member`.
The `groups_uninvite_user` and `groups_leave_group` hooks are dissimilar
enough that the potential for conflict is minimal. However, the
`groups_leave_group` and `groups_remove_member` are very similar. The only
difference being that one is initiated by the individual user, while the
other is initiated by a group/site admin. This problem presents itself in
two ways:
1) Functions hooked to both `groups_leave_group` and
`groups_remove_member` are called twice, with `groups_remove_member` being
the first action called. This occurs twice in BP core with
`bp_groups_leave_group_delete_recent_activity()` and
`groups_clear_group_user_object_cache()`. Technically, it should happen
three times, but the `bp_core_clear_cache` action for
`groups_remove_member` is missing. In each case, the function runs once on
`groups_remove_member`, then again for `groups_leave_group`, but by the
second time, the task is already complete.
2) If you're trying to target the "leave" and "remove" actions similarly,
but not exactly the same, there's no way to do this, per point one above.
In the case of #BB2488, an example use case would be to allow developers
to treat the user initiated action of leaving a public group differently
than the admin initiated action of removing the same user from a public
group. Since the leave action is typically done via UI, we can do a
`bp_current_action` check, but it's not 100% reliable, as
`groups_leave_group()` may not always be called via UI event.
The easiest solution would be to replace the `groups_remove_member()` call
with a call to `BP_Groups_Member::remove()`. The problem with that is that
we then have two nearly identical functions.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6597>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list