BP_Groups_Member::delete( int $user_id, int $group_id )

Delete a membership, based on user + group IDs.

Description

Parameters

$user_id

(int) (Required) ID of the user.

$group_id

(int) (Required) ID of the group.

Return

(True) on success, false on failure.

Source

File: bp-groups/classes/class-bp-groups-member.php

	public static function delete( $user_id, $group_id ) {
		global $wpdb;

		/**
		 * Fires before a group membership is deleted.
		 *
		 * @since BuddyPress 2.3.0
		 *
		 * @param int $user_id  ID of the user.
		 * @param int $group_id ID of the group.
		 */
		do_action( 'bp_groups_member_before_delete', $user_id, $group_id );

		$bp = buddypress();
		$remove = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );

		// Update the user's group count.
		self::refresh_total_group_count_for_user( $user_id );

		// Update the group's member count.
		self::refresh_total_member_count_for_group( $group_id );

		/**
		 * Fires after a member is removed from a group.
		 *
		 * @since BuddyPress 2.3.0
		 *
		 * @param int $user_id  ID of the user.
		 * @param int $group_id ID of the group.
		 */
		do_action( 'bp_groups_member_after_delete', $user_id, $group_id );

		return $remove;
	}

Changelog

Changelog
Version Description
BuddyPress 1.6.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.