Sorry I meant buddypress 6.2, WordPress 5.5 Not sure how I fix this post.
Please check your php error log.
And open your browser’s inspection tool and check the console for javascript errors.
Then post the error(s) here.
Thanks for your offer of help! I am not seeing php errors. As for the javascript, it pops up the box and I submit. But then the page reloads but no action occurs. I put some logging into the code (see below) It looks to me like $_REQUEST is not set and so the loop never executes at all. This returns false false false
function console_log($data){
echo '<script>';
echo 'console.log('. json_encode( $data ) .')';
echo '</script>';
}
function add_users_to_bpgroup() {
if( bp_is_active('groups') ):
console_log(isset( $_REQUEST['action'] ));
console_log(isset( $_REQUEST['bp_gid'] ));
console_log(isset( $_REQUEST['allusers'] ));
if( isset( $_REQUEST['action'] ) && isset( $_REQUEST['bp_gid'] ) && isset( $_REQUEST['allusers'] ) ) {
$group_id = $_REQUEST['bp_gid'];
$users = $_REQUEST['allusers'];
foreach ( $users as $user_id ) {
groups_join_group( $group_id, $user_id );
}
}
//form submission
add_action( 'admin_footer', function() { ?>
<script type="text/javascript" charset="utf-8">
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("Enter a Group ID","1");
jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
}
});
</script>
<?php
});
endif;
}
If it helps, I did a clean wordpress installation (5.5), with the twentytwenty theme, and the only two plugins were Loginizer and Buddypress. PHP is 7.4
I still got the same result. It ran, didn’t create any errors, but it didn’t join the user to the group.