5.x module.inc module_exists($module)
6.x module.inc module_exists($module)
7.x module.inc module_exists($module)

Determines whether a given module exists.

Parameters

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

Return value

bool TRUE if the module is both installed and enabled, FALSE otherwise.

14 calls to module_exists()
BlockTestCase::testBlockRehash in modules/block/block.test
Test _block_rehash().
CommentFieldsTest::testCommentEnable in modules/comment/comment.test
Test that comment module works when enabled after a content module.
DashboardBlocksTestCase::testDisableEnable in modules/dashboard/dashboard.test
Tests that the dashboard module can be re-enabled, retaining its blocks.
ForumTestCase::testEnableForumField in modules/forum/forum.test
Tests disabling and re-enabling the Forum module.
ModuleImplementsAlterTestCase::testModuleImplementsAlter in modules/simpletest/tests/module.test
Tests hook_module_implements_alter() adding an implementation.

... See full list

File

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

Code

function module_exists($module) {
  $list = module_list();
  return isset($list[$module]);
}

Comments

lpeabody’s picture

Will this only include enabled modules or will this include all discoverable modules?

mcrittenden’s picture

It will only return TRUE if the module is currently enabled.

batigolix’s picture

Example

if (module_exists('blog')) {
  echo 'blog module is enabled';
}
sanduhrs’s picture

That changed in Drupal 8 to

  \Drupal::moduleHandler()->moduleExists($module);

See change record https://www.drupal.org/node/1894902

JamesRobertson’s picture

system_rebuild_module_data() in modules/system.admin.in