Support » Plugin: BP Auto Group Join » Not adding new members

  • demonboy

    (@demonboy)


    I just installed this plugin and selected the option to add new members and also existing members. I updated the settings to this group and none of my members have been added.

    Any pointers?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The same happens to me. Any solution?

    So I’ve been having the same problem and I’ve done some digging.

    The way the plugin works is that it makes a call to group_accept_invite($user_id,$group_id) for each user that it is trying to add. This in turn calls accept_invitation() in the bp-invitation-manager class.

    This method checks if there is an existing invitation in the database and because the plugin has not created one first and is attempting to accept an invitation that doesn’t exist, the following code in accept_invitation() causes the acceptance to fail:

                    if ( ! $this->invitation_exists( $r ) ) {
                            return false;
                    }

    I think if the plugin is updated to create an invitation before it accepts it then the problem will go away. My guess is buddypress has recently got stricter on accepting invitations and previously it worked even if an invitation had not been generated.

    Will see if I can work out a patch/work around until maintainer fixes

    Ok, here is my attempt at a fix. I believe it works fine although no guarantees so backup your databases!

    In bp-auto-group-join-functions.php in the function bp_auto_group_join_all_members() (approx line 12 of file), I’ve updated the code that ‘accepts’ the invite so it instead reads:

                    if( !isset($membership->id) ){
                        // add as member
                        groups_join_group($group_id,$user_id);
                    }

    I believe this bypasses the invite mechanism completely. Also note I changed $member->ID to $member->id as this was a bug that caused every user to be added rather than just the new ones.

    Hope this helps.

    Thanks for your work on this, Toby. I stopped using the plugin in the end as I’ve done away with groups but if I reintroduce them I’ll be sure to try this out. Cheers.

    @tobyrussell – So I’m looking to implement your fix. Do I totally replace line 12 or do I just insert yours?

    Here is the whole function starting on line 12:

    function bp_auto_group_join_all_members( $group_id, $member_types = array() ){
        if( !isset($group_id) || empty($group_id) ) return;
    
            if( isset($member_types) && !empty($member_types) ){
                $all_users = bp_auto_group_join_get_members($member_types);
            }else{
                $all_users = bp_auto_group_join_get_members();
            }
    
            if( isset($all_users) && !empty($all_users) ){
                foreach($all_users as $single){
                    $user_id = $single;
                    // check if already member
                    $membership = new BP_Groups_Member( $user_id, $group_id );
                    if( !isset($membership->ID) ){
                        // add as member
                        groups_accept_invite($user_id, $group_id);
                    }
                }
            }
    }
    

    @tobyrussell @michaelehowe
    Any solution or answer to last question?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.