Last active
July 24, 2022 02:31
-
-
Save SitesByYogi/d231301f6590be539e8b8cbf0c84d3ae to your computer and use it in GitHub Desktop.
Remove admin menu links based on user role
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 | |
/* Remove Tools admin menu item for everyone other than Administrator */ | |
add_action( 'admin_init', 'remove_menu_pages_for_all_except_admin' ); | |
function remove_menu_pages_for_all_except_admin() { | |
global $user_ID; | |
if ( !current_user_can('administrator') ) { | |
remove_menu_page('tools.php', 'tools.php'); | |
} | |
} | |
// Most common menu items that come with WordPress | |
remove_menu_page('edit.php'); // Posts | |
remove_menu_page('upload.php'); // Media | |
remove_menu_page('link-manager.php'); // Links | |
remove_menu_page('edit-comments.php'); // Comments | |
remove_menu_page('edit.php?post_type=page'); // Pages | |
remove_menu_page('plugins.php'); // Plugins | |
remove_menu_page('themes.php'); // Appearance | |
remove_menu_page('users.php'); // Users | |
remove_menu_page('tools.php'); // Tools | |
remove_menu_page('options-general.php'); // Settings | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment