Reply To: [Resolved] How to delete specific members from a large group?
hi @palmdoc,
as expected by @henrywright, there is an easier solution from backend. I quickly tested it and it seems to work.
The snippet will add a bulk option to members list (in admin), which let you remove users from groups. Like on front-end, the admin user list is searchable by user.
Add this to bp-custom.php
// remove users from groups
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_leave_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="groupleave">Remove from BP Group</option>'));
jQuery("#doaction").click(function(e){
if(jQuery("select[name='action'] :selected").val()=="groupleave") { e.preventDefault();
gid=prompt("Please enter a BuddyPres Group ID","");
jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
}
});
</script>
<?php
});
});