0

How can I remove a menu item when admin is logged in? I used the following code but it doesn't seem to work.

function mymodule_menu_alter(&$items) {
     $items['item_x']['access callback'] = 'mymodule_menu_access_callback';
     $items['item_y']['access callback'] = 'mymodule_menu_access_callback';
}
function mymodule_menu_access_callback() {
  global $user;
  if ($user->uid == 1) {
    return FALSE;
  }
  return TRUE;
}

0

User 1 bypass access controls, so that wont work. You could have 2 menus as blocks and use the block system to control which to use.

You could also use theming/CSS to hide the menu.

0

what googletorp says is true but even more generally, you can't remove permissions to anything in drupal once they've been granted to a user (and user 1 is given all permissions).

i guess it depends whether you're just trying to hide it from display, in which case what googletorp suggests will be sufficient, or if you're actually trying to revoke access to a url from admin users.

a simple workaround (in addition to the suggestions from googletorp) to stop admins visiting said page would be to create a redirect using Rules that sends users with the admin rule somewhere else on that page.

0

You could assign a specific permission to the menu item, and then give that permission to a role that your non-admin users have.

$items['item_x']['access arguments'] = array('my special permission for this menu item');

hook_menu http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_menu/7

This will work, but keep in mind uid 1 (aka super admin) bypasses access control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.