How do I change priority of two different implementations of hook_node_access()? I am using the Node View Permissions module, which implements hook_node_access(). I am also using a custom module (mymodule.module) which is implementing the same hook. node_view_permissions_node_access() is always invoked after mymodule_node_access().

How can I change the hook invocation order? mymodule_node_access() should be executed after node_view_permissions_node_access().
Use hook_module_implements_alter():


  This hook is invoked during module_implements(). A module may implement this hook in order to reorder the implementing modules, which are otherwise ordered by the module's system weight.


Example:

function MYMODULE_module_implements_alter(&amp;$implementations, $hook) {
  if ($hook == 'node_access') {
    // Move your module's implementation to the end of the list
    $group = $implementations['MYMODULE'];
    unset($implementations['MYMODULE']);
    $implementations['MYMODULE'] = $group;
  }
}


In the possible event that another module also implements hook_module_implements_alter to move its own implementation of hook_node_access to the end of the list, you can get cunning and make sure your implementation of the alter hook runs last too:

  if ($hook == 'node_access' || $hook == 'module_implements_alter') {
    // Move your module's implementation to the end of the list
    $group = $implementations['MYMODULE'];
    unset($implementations['MYMODULE']);
    $implementations['MYMODULE'] = $group;
  }