Skip to:
Content

BuddyPress.org

Changeset 5203


Ignore:
Timestamp:
09/30/2011 10:38:56 PM (13 years ago)
Author:
djpaul
Message:

Prevent sole admins leaving groups. See #3631

Location:
branches/1.5/bp-groups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5/bp-groups/bp-groups-actions.php

    r4961 r5203  
    244244    // User wants to leave any group
    245245    if ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
    246         if ( !groups_leave_group( $bp->groups->current_group->id ) ) {
     246
     247        // Stop sole admins from abandoning their group
     248        $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
     249        if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $bp->loggedin_user->id )
     250            bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
     251
     252        elseif ( !groups_leave_group( $bp->groups->current_group->id ) )
    247253            bp_core_add_message( __( 'There was an error leaving the group.', 'buddypress' ), 'error' );
    248         } else {
     254        else
    249255            bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
    250         }
     256
    251257        bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
    252258    }
  • branches/1.5/bp-groups/bp-groups-screens.php

    r5181 r5203  
    641641                    return false;
    642642
     643                // Stop sole admins from abandoning their group
     644                $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
     645                if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id )
     646                    bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
     647
    643648                // Demote a user.
    644                 if ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) )
     649                elseif ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) )
    645650                    bp_core_add_message( __( 'There was an error when demoting that user, please try again', 'buddypress' ), 'error' );
    646651                else
Note: See TracChangeset for help on using the changeset viewer.