Skip to:
Content

BuddyPress.org

Changeset 3229


Ignore:
Timestamp:
09/02/2010 06:14:02 PM (16 years ago)
Author:
johnjamesjacoby
Message:

Fixes #2614 props Paul Gibbs

Location:
branches/1.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-groups.php

    r3218 r3229  
    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
  • branches/1.2/bp-groups/bp-groups-classes.php

    r3205 r3229  
    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;
    … …  
    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
    … …  
    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
Note: See TracChangeset for help on using the changeset viewer.