Skip to main content
2 of 5
added 565 characters in body
Aaron
  • 1.5k
  • 1
  • 9
  • 10

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is almost certainly user/%/infos instead of the more specific user/%user/infos which it would not know to register (since it doesn't know the type of wildcard represented by the %).

So try something like this:

function hide_tabs_menu_alter(&$items) { $items['user/%/infos']['access callback'] = 'hide_tabs_user_info_access_callback'; $items['user/%/infos']['access arguments'] = array(1); } function hide_tabs_user_info_access_callback($uid) { if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) { return !user_has_role($role->rid, $account); } return FALSE; } 

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) { if ($hook == 'menu_alter') { $implementation = $implementations['hide_tabs']; unset($implementations['hide_tabs']); $implementations['hide_tabs'] = $implementation; } } 
Aaron
  • 1.5k
  • 1
  • 9
  • 10