colorful-tones
6/11/2013 - 2:36 PM

Hide WordPress admin menu items from everybody but Super Admin. Helpful for hiding 'Posts' and 'Comments' menu items when client isn't using

Hide WordPress admin menu items from everybody but Super Admin. Helpful for hiding 'Posts' and 'Comments' menu items when client isn't using blog. Change unfiltered_html to install_plugins if you want to all Admins access to menu items too, etc.

// hide the Posts and Comments menu items from ALL roles except Super Admin
// https://codex.wordpress.org/Roles_and_Capabilities
function remove_menus () {
    global $menu;
    if( (current_user_can('unfiltered_html')) ) { $restricted = array(__()); }
    else { $restricted = array( __('Posts'),__('Comments')); } // hide these for other roles
    end ($menu);
    while (prev($menu)) {
        $value = explode(' ',$menu[key($menu)][0]);
    
        if(in_array($value[0] != NULL?$value[0]:'' , $restricted)){unset($menu[key($menu)]);
        }
    }
}
add_action('admin_menu', 'remove_menus');