1444 | | groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 ); |
| 1440 | if ( groups_is_user_admin( $user_id, $group_id ) ) { |
| 1441 | // If the user is a sole group admin, install a site admin as their replacement. |
| 1442 | if ( count( groups_get_group_admins( $group_id ) ) < 2 ) { |
| 1443 | $admin = get_users( [ |
| 1444 | 'blog_id' => bp_get_root_blog_id(), |
| 1445 | 'fields' => 'id', |
| 1446 | 'number' => 1, |
| 1447 | 'orderby' => 'ID', |
| 1448 | 'role' => 'administrator', |
| 1449 | ] ); |
1446 | | // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync. |
1447 | | 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 ) ) |
1448 | | groups_delete_group( $group_id ); |
| 1451 | if ( ! empty( $admin ) ) { |
| 1452 | groups_join_group( $group_id, $admin[0] ); |
| 1453 | groups_promote_member( $admin[0], $group_id, 'admin' ); |
| 1454 | } |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | groups_leave_group( $group_id, $user_id ); |