Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am running a multisite install with domain mapping and W3 Total Cache set up on each of the sites. I don't use a network in the traditional sense - each site is generally independent. I only have the second checkbox checked in "Domain Options" for the mapping plugin, if that gives you any sort of idea.

Each site's administrators can still see the Performance menu and change its options, however. I would like to disable this.

Best method?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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';
        }
    }
}
share|improve this answer
    
Have you tried accessing the page as - for example - subscriber? I think it would work, as only the cap is left and the system can't really indentify what's going on in here. I think it would better work if you're only hiding it via css or js, but still changing the caps like you've shown ↑ above. Btw: I'd set the priority for the hook to a pretty high number to avoid overriding through other code. –  kaiser Mar 7 '12 at 7:52
    
when i access the page as an editor i get "You do not have sufficient permissions to access this page." i totally had a higher priority and took it off, will put it back. why would js/css be better? –  helgatheviking Mar 7 '12 at 14:02
    
I was just curious what happens if you remove the entire $submenu-entry using remove_menu_page() and then add only the capability in again. –  kaiser Mar 7 '12 at 14:16
    
This works for me because I'm not concerned about my users from a security perspective, but it does not remove the capability of a site admin from going to the page if the url is known. –  kenny Mar 8 '12 at 2:51
    
it prevents every one who is not a network admin, so if your individual site owners are super admins they'd still be able to get to the pages. though you could tweak it to check for a specific user... such as yourself and deny it to everyone else. $current_user = wp_get_current_user(); if($current_user->user_login != 'yourusername' ) –  helgatheviking Mar 8 '12 at 3:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.