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 would like to be able to hide W3 Total Cache from non admins. How can I go about doing so?

The following code I tried implementing in my functions.php file does not work:

function hide_w3tc() {
    if (!current_user_can('super_admin')) {
        remove_submenu_page('admin.php?page=w3tc_dashboard');
    } 
}

add_action( 'admin_menu', 'hide_w3tc');
share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can try to use remove_menu_page(), so you code example would be like:

function hide_w3tc() {
    if (!current_user_can('manage_network')) {
        remove_menu_page('w3tc_dashboard');
    } 
}
add_action( 'admin_menu', 'hide_w3tc',11);

where we use a priority greater than the default of 10, since the W3TC menu page is added via

add_menu_page('Performance', 'Performance', 'manage_options', 'w3tc_dashboard', '', 'div');
share|improve this answer
    
This seems to work, thank you. –  Matt Mar 26 '13 at 17:14
1  
ok great, by the way you are using a 'super_admin' capability but I usually see the 'manage_network' capability used instead. –  birgire Mar 26 '13 at 17:28
    
I used super_admin as I made a custom user group. I suppose manage_network has more coverage of all the permissions underneath that umbrella? –  Matt Mar 26 '13 at 17:31
1  
ok I was just wondering where it came from, since it is not listed here: codex.wordpress.org/Roles_and_Capabilities ;-) –  birgire Mar 26 '13 at 17:32

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.