Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick users page mod to allow for bulk adding to BuddyPress groups.
<?php
add_action('load-users.php',function() {
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( $group_id, $user_id );
}
}
//Add some Javascript to handle the form submission
add_action('admin_footer',function(){ ?>
<script>
jQuery("select[name='action']").append(jQuery('<option value="groupadd">Add to BP Group</option>'));
jQuery("#doaction").click(function(e){
if(jQuery("select[name='action'] :selected").val()=="groupadd") { e.preventDefault();
gid=prompt("Please enter a BuddyPres Group ID","1");
jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
}
});
</script>
<?php
});
});
@STRAND-C

This comment has been minimized.

Copy link

@STRAND-C STRAND-C commented Sep 23, 2015

Does this work for more than 100 users in one go? I tried 165 but it didn't work? Batches of 50 did though :)

@Spirencreative

This comment has been minimized.

Copy link

@Spirencreative Spirencreative commented May 22, 2019

Will this work with the current version of buddypress Version 4.3.0 . I see this was written 4 years ago. If so where would I place the bp-bulk-add-users.php file? Thanks for the help.

@vivekmathur1969

This comment has been minimized.

Copy link

@vivekmathur1969 vivekmathur1969 commented Feb 26, 2020

Hi - just a quick query if this still works? I am on BP 5.1.2 and added this to functions.php. I do get the option in Bulk Actions, and the form for the Group ID, but after processing that the member is not added to the groups? Does something need to be changed? Any advice would be hugely appreciated. thanks!

@rohmann

This comment has been minimized.

Copy link
Owner Author

@rohmann rohmann commented Feb 26, 2020

I'm honestly not sure, sorry. I'd start by checking BuddyPress source for the groups_join_group function and see if anything has changed there.

@vivekmathur1969

This comment has been minimized.

Copy link

@vivekmathur1969 vivekmathur1969 commented Feb 26, 2020

Thanks very much, Rohmann. Will check that out, and update here if I find anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment