1

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');

1 Answer 1

3

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');
3
  • 1
    ok great, by the way you are using a 'super_admin' capability but I usually see the 'manage_network' capability used instead.
    – birgire
    Commented Mar 26, 2013 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
    Commented Mar 26, 2013 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
    Commented Mar 26, 2013 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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