Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Hide menu items for non-admin users WordPress
// remove unnecessary menus
function remove_admin_menus () {
global $menu;
// all users
$restrict = explode(',', 'Links,Comments');
// non-administrator users
$restrict_user = explode(',', 'Media,Profile,Appearance,Plugins,Users,Tools,Settings');
// WP localization
$f = create_function('$v,$i', 'return __($v);');
array_walk($restrict, $f);
if (!current_user_can('activate_plugins')) {
array_walk($restrict_user, $f);
$restrict = array_merge($restrict, $restrict_user);
// remove menus
while (prev($menu)) {
$k = key($menu);
$v = explode(' ', $menu[$k][0]);
if(in_array(is_null($v[0]) ? '' : $v[0] , $restrict)) unset($menu[$k]);
add_action('admin_menu', 'remove_admin_menus');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.