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

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

Parameters

$group_id

(Required) ID of the group.

$user_id

(Required) ID of the user leaving the group.

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' ) ) {
		return;
	}

	// 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
		) );
	}
}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.