Skip to:
Content

BuddyPress.org

Ticket #2614: patch-2614.patch

File patch-2614.patch, 1.4 KB (added by DJPaul, 14 years ago)

v1

  • bp-groups/bp-groups-classes.php

     
    10711071                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
    10721072        }
    10731073
     1074        /**
     1075         * Delete all group membership information for the specified user
     1076         *
     1077         * @global object $bp BuddyPress global settings
     1078         * @global wpdb $wpdb WordPress database object
     1079         * @param int $user_id
     1080         * @since 1.0
     1081         * @uses BP_Groups_Member
     1082         */
    10741083        function delete_all_for_user( $user_id ) {
    1075                 global $wpdb, $bp;
     1084                global $bp, $wpdb;
    10761085
    10771086                // Get all the group ids for the current user's groups and update counts
    10781087                $group_ids = BP_Groups_Member::get_group_ids( $user_id );
    10791088                foreach ( $group_ids['groups'] as $group_id ) {
    10801089                        groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 );
     1090
     1091                        // If current user is the sole admin of a group, delete that group to avoid counts going out-of-sync
     1092                        if ( groups_is_user_admin( $user_id, $group_id ) && count( groups_get_group_admins( $group_id ) ) < 2 )
     1093                                groups_delete_group( $group_id );
    10811094                }
    10821095
    10831096                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id ) );