Skip to:
Content

BuddyPress.org

Changeset 6013


Ignore:
Timestamp:
05/03/2012 02:34:31 PM (12 years ago)
Author:
boonebgorges
Message:

In groups_accept_invite(), if the user is already a group member, do some cleanup and return true. Prevents bugs related to duplicate uncleared membership requests/invitations. Fixes #4182

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-functions.php

    r6012 r6013  
    324324        $user_id = bp_loggedin_user_id();
    325325
    326     // Check if the user has an outstanding invite, is so delete it.
     326    // Check if the user has an outstanding invite. If so, delete it.
    327327    if ( groups_check_user_has_invite( $user_id, $group_id ) )
    328328        groups_delete_invite( $user_id, $group_id );
    329329
    330     // Check if the user has an outstanding request, is so delete it.
     330    // Check if the user has an outstanding request. If so, delete it.
    331331    if ( groups_check_for_membership_request( $user_id, $group_id ) )
    332332        groups_delete_membership_request( $user_id, $group_id );
     
    606606}
    607607
     608/**
     609 * Process the acceptance of a group invitation.
     610 *
     611 * Returns true if a user is already a member of the group.
     612 *
     613 * @param int $user_id
     614 * @param int $group_id
     615 * @return bool True when the user is a member of the group, otherwise false
     616 */
    608617function groups_accept_invite( $user_id, $group_id ) {
    609618    global $bp;
    610619
    611     if ( groups_is_user_member( $user_id, $group_id ) )
    612         return false;
     620    // If the user is already a member (because BP at one point allowed two invitations to
     621    // slip through), delete all existing invitations/requests and return true
     622    if ( groups_is_user_member( $user_id, $group_id ) ) {
     623        if ( groups_check_user_has_invite( $user_id, $group_id ) )
     624            groups_delete_invite( $user_id, $group_id );
     625
     626        if ( groups_check_for_membership_request( $user_id, $group_id ) )
     627            groups_delete_membership_request( $user_id, $group_id );
     628
     629        return true;
     630    }
    613631
    614632    $member = new BP_Groups_Member( $user_id, $group_id );
Note: See TracChangeset for help on using the changeset viewer.