Skip to:
Content
Pages
Categories
Search
Top
Bottom

Protect Groups From Deletion in Admin Dashboard


  • ToobHed
    Participant

    @toobhed

    Is there any way to protect a group from being deleted in the admin dashboard by anyone other than an administrator? I am using Members to create roles for my site admins (with restricted permissions), and I want to prevent these groups from being deleted by anyone less than a user with the highest level of permissions which for my site is the role Administrator.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

  • Henry Wright
    Moderator

    @henrywright

    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.


    ToobHed
    Participant

    @toobhed

    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!


    danbp
    Participant

    @danbp

    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.


    ToobHed
    Participant

    @toobhed

    Thanks for the help, I just decided to redirect them to a post with the desired error message.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar