bp_groups_leave_group_delete_recent_activity( int $group_id, int $user_id )

Delete group member activity if they leave or are removed within 5 minutes of membership modification.

Description Description

If the user joined this group less than five minutes ago, remove the joined_group activity so users cannot flood the activity stream by joining/leaving the group in quick succession.

Top ↑

Parameters Parameters


(int) (Required) ID of the group.


(int) (Required) ID of the user leaving the group.

Source Source

File: bp-groups/bp-groups-activity.php

function bp_groups_leave_group_delete_recent_activity( $group_id, $user_id ) {

	// Bail if Activity component is not active.
	if ( ! bp_is_active( 'activity' ) ) {

	// Get the member's group membership information.
	$membership = new BP_Groups_Member( $user_id, $group_id );

	// Check the time period, and maybe delete their recent group activity.
	if ( time() <= strtotime( '+5 minutes', (int) strtotime( $membership->date_modified ) ) ) {
		bp_activity_delete( array(
			'component' => buddypress()->groups->id,
			'type'      => 'joined_group',
			'user_id'   => $user_id,
			'item_id'   => $group_id
		) );

Top ↑

Changelog Changelog

Version Description
1.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.