Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Restricts certain menu items from appearing the WordPress Admin area. Useful for hiding unused features such as Posts or Comments from non-Administrator users.
<?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' );
@fjarrett

This comment has been minimized.

Copy link
Owner Author

@fjarrett fjarrett commented Mar 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment