I am trying to hide a certain amount of menus for a client. Right now I am using the following code and it is doing its job well, but it removes it for everyone as far as I can tell. As in all roles.
function remove_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Media'), __('Links'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Profile'),__('Plugins'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
add_action('admin_menu', 'remove_menus');
What is the line I would use to have this call out only an editor or an author etc?
Thanks much
you can do this, it hides the menu (thats all , they can still go to the menu url if they know it), based on capability. You can easily change it to role or even username.
I think user role is “user_role” and for username it is “user_login”. The example below uses “user_level” of 10 meaning everyone but the admin.
Use the
current_user_can()
function to build that$restricted
array in pieces, before you pass it through that unset loop. You’ll have to use capabilities, and not role names, to make it work.If you dont mind using a plugin instead of hard-code try using:
http://wordpress.org/extend/plugins/adminimize/
I use it for all the sites I create to customize what the different roles see, it gives you alot of options and not just on the menus.