Skip to content

Instantly share code, notes, and snippets.

@WPsites
Created November 22, 2012 01:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WPsites/4128809 to your computer and use it in GitHub Desktop.
Save WPsites/4128809 to your computer and use it in GitHub Desktop.
Hide admin menu items on a WordPress site.
<?php
/*
The code below hides the admin menu items for all users that don't have the 'manage_sites' capability.
On multisite that would mean only Super Admins can look at those menu items
This script only removes the menu items so users can still look at the page if they know the path, but it de-clutters the admin
*/
global $current_user;
if ( !current_user_can('manage_sites') ) {
add_action( 'admin_menu', 'bones_my_remove_menu_pages', 9999 );
function bones_my_remove_menu_pages() {
global $menu;
//regular expression of menu items that need removing (by name/label)
$page_labels = "#(Forms|Custom Types|Appearance|Plugins|Tools|Settings|Performance|WPide|Seo)#i";
foreach ( $menu as $i => $item ) {
if ( preg_match($page_labels, $item[0]) >0 ) {
unset( $menu[$i] );
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment