Skip to content

Instantly share code, notes, and snippets.

@luclemo
Forked from frankiejarrett/gist:5224398
Last active June 3, 2016 12:39
Show Gist options
  • Save luclemo/7a7f99aeda98cc876a6a to your computer and use it in GitHub Desktop.
Save luclemo/7a7f99aeda98cc876a6a to your computer and use it in GitHub Desktop.
Remove menu items from the WP dashboard (ex: remove posts & comments if client doesn't blog) #wordpress
<?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