Skip to:
Content

BuddyPress.org

Ticket #6209: 6209-groups-leave-group.11.patch

File 6209-groups-leave-group.11.patch, 1.8 KB (added by dcavins, 5 years ago)

Use groups_remove_member() in groups_leave_group(). Also change groups_remove_member() to allow it to work in more situations.

  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index 8b19738..283392b 100644
    function groups_leave_group( $group_id, $user_id = 0 ) { 
    431431                }
    432432        }
    433433
    434         // This is exactly the same as deleting an invite, just is_confirmed = 1 NOT 0.
    435         if ( !groups_uninvite_user( $user_id, $group_id ) ) {
     434        if ( ! groups_remove_member( $user_id, $group_id ) ) {
    436435                return false;
    437436        }
    438437
    function groups_unban_member( $user_id, $group_id ) { 
    14011400 */
    14021401function groups_remove_member( $user_id, $group_id ) {
    14031402
    1404         if ( ! bp_is_item_admin() )
    1405                 return false;
     1403        if ( ! bp_is_item_admin() ) {
     1404                // bp_is_item_admin may not be set if this function is called outside of group context.
     1405                // Site admins and group admins can remove a member from a group.
     1406                // A member may also request to remove herself from a group.
     1407                if ( ! current_user_can( 'bp_moderate' )
     1408                        && ! groups_is_user_admin( bp_loggedin_user_id(), $group_id )
     1409                        && $user_id != bp_loggedin_user_id() ) {
     1410                                return false;
     1411                        }
     1412        }
    14061413
    14071414        $member = new BP_Groups_Member( $user_id, $group_id );
    14081415
  • tests/phpunit/testcases/groups/functions.php

    diff --git tests/phpunit/testcases/groups/functions.php tests/phpunit/testcases/groups/functions.php
    index 8d9e990..f73766b 100644
    class BP_Tests_Groups_Functions extends BP_UnitTestCase { 
    3737                groups_join_group( $g1, $u2 );
    3838                groups_join_group( $g2, $u2 );
    3939
     40                // Set the current user so the leave group request goes through.
     41                $this->set_current_user( $u2 );
    4042                groups_leave_group( $g1, $u2 );
    4143                $this->assertEquals( 1, bp_get_user_meta( $u2, 'total_group_count', true ) );
    4244        }