I will show you how to make it in this post. We just add a little piece of code to your theme
functions.php file. Let’s go.
Open your blog current theme functions.php file. And put into begin of it following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // block profile menu for users with role subscriber if ( is_user_logged_in() ) { $userRole = ($current_user->data->wp_capabilities); $role = key($userRole); unset($userRole); if ($role=='subscriber') { function remove_profile_submenu() { global $submenu; //remove Your profile submenu item unset($submenu['profile.php'][5]); } add_action('admin_head', 'remove_profile_submenu'); function remove_profile_menu() { global $menu; // remove Profile top level menu unset($menu[70]); } add_action('admin_head', 'remove_profile_menu'); function profile_redirect() { $result = stripos($_SERVER['REQUEST_URI'], 'profile.php'); if ($result!==false) { wp_redirect(get_option('siteurl') . '/wp-admin/index.php'); } } add_action('admin_menu', 'profile_redirect'); } } // end of block profile menu for users with role |
That’s it. This code snippet blocks user profile editor for all users with subscriber role. I use subscriber role just for example. It can be any another role including your own custom made one. To create your own user role and fill it with capabilities as you and only you wish, use User Role Editor plugin.
Let’s look inside the code.
1st, at lines 3-6 we check what role current logged-in user has. At line 3
3 | $userRole = ($current_user->data->wp_capabilities); |
you should change wp_ to your own WordPress database prefix if it is different than a default one.
To check another role than subscriber, change role name to that you wish at line 6:
6 | if ($role=='role_you_wish_name') { |
Then lines 7-12 removes ‘Your profile’ submenu item.
Lines 14-19 removes ‘Profile’ top level menu.
Is it enough and can we finish here? No. We just hide menu items from user. But he/she still can call wp-admin/profile.php directly from the browser. At lines 22-29 we redirect user to admin back-end dashboard if he/she tries to call profile.php script.
To block another menu item than “Profile” look into wp-admin/menu.php file from WordPress core and select one you like more
.
The code I wrote above is tested against WordPress 2.9.2.
Thanks to Clay for general idea and useful post Remove WordPress Admin Menu Without Affecting WordPress Core System which was written directly on discussed subject.





