Skip to:
Content

BuddyPress.org

Ticket #2614: patch-2614-2.patch

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

v2

  • bp-groups.php

     
    19081908        return BP_Groups_Member::check_is_banned( $user_id, $group_id );
    19091909}
    19101910
     1911/**
     1912 * Is the specified user the creator of the group?
     1913 *
     1914 * @param int $user_id
     1915 * @param int $group_id
     1916 * @since 1.2.6
     1917 * @uses BP_Groups_Member
     1918 */
     1919function groups_is_user_creator( $user_id, $group_id ) {
     1920        return BP_Groups_Member::check_is_creator( $user_id, $group_id );
     1921}
     1922
    19111923/*** Group Activity Posting **************************************************/
    19121924
    19131925function groups_post_update( $args = '' ) {
  • bp-groups/bp-groups-classes.php

     
    979979                return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
    980980        }
    981981
     982        /**
     983         * Is the specified user the creator of the group?
     984         *
     985         * @global object $bp BuddyPress global settings
     986         * @global wpdb $wpdb WordPress database object
     987         * @param int $user_id
     988         * @param int $group_id
     989         * @since 1.2.6
     990         */
     991        function check_is_creator( $user_id, $group_id ) {
     992                global $bp, $wpdb;
     993
     994                if ( !$user_id )
     995                        return false;
     996
     997                return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
     998        }
     999
    9821000        function check_for_membership_request( $user_id, $group_id ) {
    9831001                global $wpdb, $bp;
    9841002
     
    10711089                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
    10721090        }
    10731091
     1092        /**
     1093         * Delete all group membership information for the specified user
     1094         *
     1095         * @global object $bp BuddyPress global settings
     1096         * @global wpdb $wpdb WordPress database object
     1097         * @param int $user_id
     1098         * @since 1.0
     1099         * @uses BP_Groups_Member
     1100         */
    10741101        function delete_all_for_user( $user_id ) {
    1075                 global $wpdb, $bp;
     1102                global $bp, $wpdb;
    10761103
    10771104                // Get all the group ids for the current user's groups and update counts
    10781105                $group_ids = BP_Groups_Member::get_group_ids( $user_id );
    10791106                foreach ( $group_ids['groups'] as $group_id ) {
    10801107                        groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 );
     1108
     1109                        // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync
     1110                        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 ) )
     1111                                groups_delete_group( $group_id );
    10811112                }
    10821113
    10831114                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id ) );