BP_Groups_Member::delete_all_for_user( int $user_id )
Delete all group membership information for the specified user.
Description
In cases where the user is the sole member of a group, a site administrator is assigned to be the group’s administrator. Unhook groups_remove_data_for_user()
to modify this behavior.
Parameters
- $user_id
-
(Required) ID of the user.
Return
(bool)
Source
File: bp-groups/classes/class-bp-groups-member.php
public static function delete_all_for_user( $user_id ) { global $wpdb; $bp = buddypress(); // Get all the group ids for the current user's groups and update counts. $group_ids = BP_Groups_Member::get_group_ids( $user_id ); foreach ( $group_ids['groups'] as $group_id ) { groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 ); // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync. if ( groups_is_user_admin( $user_id, $group_id ) && count( groups_get_group_admins( $group_id ) ) < 2 && groups_is_user_creator( $user_id, $group_id ) ) groups_delete_group( $group_id ); } return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id ) ); }
Changelog
Version | Description |
---|---|
BuddyPress 4.0.0 The method behavior was changed so that single-member groups are not deleted. | BuddyPress 4.0.0 The method behavior was changed so that single-member groups are not deleted. |
BuddyPress 1.0.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.