Same name and namespace in other branches
  1. 4.6.x includes/module.inc \module_hook()
  2. 4.7.x includes/module.inc \module_hook()
  3. 5.x includes/module.inc \module_hook()
  4. 6.x includes/module.inc \module_hook()

Determines whether a module implements a hook.

Parameters

$module: The name of the module (without the .module extension).

$hook: The name of the hook (e.g. "help" or "menu").

Return value

TRUE if the module is both installed and enabled, and the hook is implemented in that module.

Related topics

6 calls to module_hook()
drupal_check_module in includes/install.inc
Checks a module's requirements.
module_disable in includes/module.inc
Disables a given set of modules.
module_invoke in includes/module.inc
Invokes a hook in a particular module.
node_hook in modules/node/node.module
Determines whether a node hook exists.
search_data in modules/search/search.module
Performs a search by calling hook_search_execute().

... See full list

File

includes/module.inc, line 688
API for loading and interacting with Drupal modules.

Code

function module_hook($module, $hook) {
  $function = $module . '_' . $hook;
  if (function_exists($function)) {
    return TRUE;
  }

  // If the hook implementation does not exist, check whether it may live in an
  // optional include file registered via hook_hook_info().
  $hook_info = module_hook_info();
  if (isset($hook_info[$hook]['group'])) {
    module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);
    if (function_exists($function)) {
      return TRUE;
    }
  }
  return FALSE;
}