Created
November 22, 2012 01:03
-
-
Save WPsites/4128809 to your computer and use it in GitHub Desktop.
Hide admin menu items on a WordPress site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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