If a non-admin user tries to delete a group from within the admin area, they’ll get redirected to your home page.
add_action( 'groups_before_delete_group', function() {
if ( ! is_admin() ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_redirect( home_url() );
exit;
}
} );
Note: I haven’t tested. This is quite a crude solution; instead of redirecting the user a better approach would be to add an admin notice letting the user know they can’t delete the group.
Thanks for the help, pointing out groups_before_delete_group got me in the right direction. It would be nice as you pointed out to give a message, but for now, I only have a few admins, and simply want to block some core groups and this solves my problem.
I messed around with trying to put in an admin notice but it seems when I exit the function it goes to a blank page. I’m no expert, I am sure there is an answer but for now this keeps my admins from deleting the important groups.
Thanks!
Hi,
give this a try. Add to bp-custom.php. The action hook is in bp-groups-admin.php
function my_groups_admin_notice() {
echo '<div><p>Hello group admins !</p></div>';
}
add_action( 'bp_groups_admin_index', 'my_groups_admin_notice' );
Text will show up above the page title.
Thanks for the help, I just decided to redirect them to a post with the desired error message.