Skip to content

Instantly share code, notes, and snippets.

@schutzsmith
Created April 14, 2019 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schutzsmith/797670b4cb1cba6e17bb7e9166d2e154 to your computer and use it in GitHub Desktop.
Save schutzsmith/797670b4cb1cba6e17bb7e9166d2e154 to your computer and use it in GitHub Desktop.
remove unnecessary menus in WordPress
// remove unnecessary menus
function remove_admin_menus () {
global $menu;
// all users
$restrict = explode(',', 'Links,Comments');
// non-administrator users
$restrict_user = explode(',', 'Media,Profile,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
end($menu);
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