Youzify (formerly Youzer)

How to Add Users to BuddyPress Groups in Bulk

1. Please go to your Cpanel/FTP, and go to folder "wp-content/plugins"

2. Create a new file and name it with "bp-custom.php"

3. Paste this file into the folder

function add_users_to_bpgroup() {   
    if( bp_is_active('groups') ):
        if( isset( $_GET['action'] ) && isset( $_GET['bp_gid'] ) && isset( $_GET['users'] ) ) {
            $group_id = $_GET['bp_gid'];
            $users = $_GET['users'];
            foreach ( $users as $user_id) {
                groups_join_group( intval($group_id), $user_id );
            }            
        }
         
    endif;
};
add_action ( 'load-users.php', 'add_users_to_bpgroup', 999 );
 
function add_users_to_bpgroup_js() { ?>
<script type="text/javascript" charset="utf-8">
    jQuery("select[name='action']").append(jQuery('<option value="groupadd">Add to Group</option>'));
    jQuery("#doaction").click(function(e){
        if(jQuery("select[name='action'] :selected").val()=="groupadd") { e.preventDefault();
            gid=prompt("Enter a Group ID","1");
            jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
        }
    });
</script>
<?php
};
add_action( 'admin_footer', 'add_users_to_bpgroup_js', 999 );

4. The JavaScript portion of the snippet adds a new item to the Bulk Actions drown-down menu named Add to BP Group.

5. Select the users you want to add to a group and select Add to BP Group. A prompt appears asking for the Buddy Group ID you want to assign the users to.

6. To locate the Group ID, click on the Groups admin menu and click on the group’s name. The URL will look something like this admin.php?page=bp-groups&gid=357&action=edit and the ID is the number that appears after gid=. After entering the ID number, click the Ok button. All of the users you selected will be assigned to that group.