W3 Total Cache – How to disable “Performance” menu under multisite? [closed]

i don’t know if it is the best method, but something i just did recently (having picked it up from an answer here) was to remove the menu page if certain conditions aren’t met and also to update the caps on all the removed pages so that they can’t be accessed by someone slick enough to remember the URLs.

add_action('admin_menu', 'wpa_44698',999);

function wpa_44698(){  
global $submenu; 
    //only show w3tc_general options to network admins in multisite
    if ( is_multisite() && !current_user_can( 'manage_network' ) ) {
        remove_menu_page('w3tc_general');

        // Still need to update cap requirements even when hidden
        if(isset($submenu['w3tc_general'])) foreach( $submenu['w3tc_general'] as $position => $data ) {
            $submenu['w3tc_general'][$position][1] = 'manage_network';
        }
    }
}

edit: i have no idea if this is any ‘better’ but it also seems to work.

add_action('admin_menu', 'wpa_44698',999);

function wpa_44698(){  
    global $submenu; 
    //only show w3tc_general options to network admins in multisite
    if ( is_multisite() && !current_user_can( 'manage_network' ) && isset($submenu['w3tc_general']) ) {
        foreach( $submenu['w3tc_general'] as $position => $data ) {       
            remove_menu_page($data[2]);
            $submenu['w3tc_general'][$position][1] = 'manage_network';
        }
    }
}

Leave a Comment