Change WordPress user roles and capabilities Forums How to or FAQ Multisite – How to remove the options to "delete site" ?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3573
    pazazta
    Participant

    Hey,
    I’m using your plugin on multisite and need your help please:
    On all subsites there is an option under “Tools” which called “Delete Site” (it’s built in within wordpress). I want to remove it for all websites and don’t know how because it’s doesn’t show on the main site and doesn’t show on network (obviously we can’t delete the main site).

    I was able to remove this option by revoking “manage options” but in this case I can’t allow Yoast SEO for a specific role (or any other plugin which use ‘manage options’)

    If I enter the subsite options I can remove the “Delete Site” option under “Admin Menu” (but I can’t go over all my subsites and do it manually, I have many and I’m adding new ones frequently)

    How can I remove the “Delete Site” option ?
    Thank you

    #3574
    Vladimir
    Keymaster

    Hi,

    Try this workaround:

    
    <?php
    
    add_action('map_meta_cap', 'ure_exclude_delete_site_cap', 10, 4);
    
    function ure_exclude_delete_site_cap($caps, $cap, $user_id, $args) {
            
        if (!is_admin()) {
            return $caps;
        }
        if (is_super_admin()) {
            return $caps;
        }
        
        if ($cap==='delete_site') {
            $caps = array('do_not_allow');
        }
        
        return $caps;    
    }
    

    Setup this code as a Must Use plugin. In short, place it into .php file at wp-content/mu-plugins/ folder.

    #3575
    pazazta
    Participant

    Thank you Vladimir!
    Works perfectly !

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.