Restrict admin menu items by username

WordPress Tutorial – Adding this PHP code to the functions.php of your wordpress admin will allow you to restrict access to menu items based on username.



function remove_menus()
global $menu;
global $current_user;
if($current_user->user_login == 'username')
$restricted = array(__('Posts'),
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}// end while
}// end if
add_action('admin_menu', 'remove_menus');

Leave a comment