reference: http://frankiejarrett.com/remove-specific-menu-items-from-the-wordpress-admin/
-
-
Save theodorocaliari/a40c807e2b83d2324890 to your computer and use it in GitHub Desktop.
Customize Wordpress Admin Menu for Users
This file contains hidden or 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