I'm trying to hide certain admin menu items in Wordpress from all users except one (myself).
I can find various tutorials but they mostly hide on user roles rather than users.
I have found this from the Wordpress codex:
<?php
function custom_menu_page_removing() {
remove_menu_page( $menu_slug );
}
add_action( 'admin_menu', 'custom_menu_page_removing' );
?>
But I don't fully understand it, plus I think I'll need to add some more PHP to it to essentially make the code say:
If user isn't [email protected] (Me!)
Then remove these menu items:
ItemID 1, ItemID 2, ItemID 3, etc...
Can anyone help?
You can check for the user id:
// admin_init action works better than admin_menu in modern wordpress (at least v5+)
add_action( 'admin_init', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
global $user_ID;
if ( $user_ID != 1 ) { //your user id
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With