programmatically disable menu based on user taxonomy reference fields I am trying to programmatically disable menu based on account settings/user taxonomy term field, is there a better way to do it? do I need to use hook menu? to disable already built menu, as I have a lot of users in department that needs to get filtered to only show the menu they can edit

UPDATE :

I wanted to hook the permisssion of user so not all can edit the menu structure, like edit links and so on, like example I allowed permissions manage menu 1, manage menu 2, for role a, then I wanted to hook that menu 1 is only available for user with term reference 1. something like that

thank you!
The answer will depend on what your created menu items route to (hook_menu() is for defining new menus so it won't help you here).

Generically, hook_menu_alter() allows you to alter the access callback so that you can override access with your own logic. If the path you're overriding is specific to a special module route (e.g. admin/dashboard), then it would make sense to use this hook.

/**
 * Implements hook_menu_alter().
 */
function MYMODULE_menu_alter(&amp;$items) {
  $items['admin/dashboard']['access callback'] = 'MYMODULE_access';
}

/**
 * Access callback function
 */
function MYMODULE_access() {
  global $user;
  $user_entity = user_load($user-&gt;uid);

  // @TODO: Check your user entity's taxonomy field for access and return
  // TRUE | FALSE

  // EXAMPLE: Allow access for USER #123
  // return ($user_entity-&gt;uid == 123);
}


If your created menu items link to content nodes then you should look at hook_node_access(). This hook is specifically designed for controlling access to nodes so you'll have access to the node/user object from the hook's arguments.

/**
 * Implements hook_node_access().
 */
function MYMODULE_node_access($node, $op, $account) {
  $user_entity = user_load($account-&gt;uid);

  // @TODO: Check your user entity's taxonomy field for access and return
  // NODE_ACCESS_ALLOW | NODE_ACCESS_DENY | NODE_ACCESS_IGNORE
  // depending on your logic
}