Skip to content

Instantly share code, notes, and snippets.

@jbreitenbucher
Created May 16, 2012 14:57
Show Gist options
  • Save jbreitenbucher/2710977 to your computer and use it in GitHub Desktop.
Save jbreitenbucher/2710977 to your computer and use it in GitHub Desktop.
WordPress:Limit Administration Menus by Role
function jb_remove_menus_by_role () {
global $menu;
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if($user_role == 'xxx') {
$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('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)]);}
} //end while
}//end if
}
add_action('admin_menu', 'jb_remove_menus_by_role');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment