Last active
December 15, 2015 07:38
-
-
Save frankiejarrett/5224398 to your computer and use it in GitHub Desktop.
Restricts certain menu items from appearing the WordPress Admin area. Useful for hiding unused features such as Posts or Comments from non-Administrator users.
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 | |
/** | |
* Restricts certain menu items from appearing the WP Admin area. Does not | |
* affect Administrator users. | |
* | |
* @action admin_menu | |
*/ | |
function fjarrett_restrict_admin_menu_items() { | |
// Don't restrict Administrator users. | |
if ( current_user_can( 'manage_options' ) ) | |
return; | |
// Array of the menu item slugs you want to remove. | |
$restricted = array( | |
'menu-posts', // Posts | |
'menu-comments', // Comments | |
); | |
global $menu; | |
foreach ( $menu as $item => $data ) { | |
if ( ! isset( $data[5] ) ) { | |
continue; // Move along if the current $item doesn't have a slug. | |
} elseif ( in_array( $data[5], $restricted ) ) { | |
unset( $menu[$item] ); // Remove the current $item from the $menu. | |
} | |
} | |
} | |
add_action( 'admin_menu', 'fjarrett_restrict_admin_menu_items' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally posted on: http://frankiejarrett.com/remove-specific-menu-items-from-the-wordpress-admin/