Skip to content

Instantly share code, notes, and snippets.

@colorful-tones
Created June 11, 2013 14:36
Show Gist options
  • Save colorful-tones/5757341 to your computer and use it in GitHub Desktop.
Save colorful-tones/5757341 to your computer and use it in GitHub Desktop.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment