5.x module.inc module_disable($module_list)
6.x module.inc module_disable($module_list)
7.x module.inc module_disable($module_list, $disable_dependents = TRUE)

Disables a given set of modules.


string[] $module_list: An array of module names.

bool $disable_dependents: If TRUE, dependent modules will automatically be added and disabled in the correct order. This incurs a significant performance cost, so use FALSE if you know $module_list is already complete and in the correct order.

See also



12 calls to module_disable()
EnableDisableTestCase::testEntityInfoChanges in modules/system/system.test
Ensures entity info cache is updated after changes.
FieldCrudTestCase::_testActiveHelper in modules/field/tests/field.test
Helper function for testActive().
FieldInfoTestCase::testInstanceDisabledEntityType in modules/field/tests/field.test
Test that instances on disabled entity types are filtered out.
LocaleUninstallFunctionalTest::testUninstallProcess in modules/locale/locale.test
Check if the values of the Locale variables are correct after uninstall.
ModuleUninstallTestCase::testUserPermsUninstalled in modules/simpletest/tests/module.test
Tests the hook_modules_uninstalled() of the user module.

... See full list


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


function module_disable($module_list, $disable_dependents = TRUE) {
  if ($disable_dependents) {

    // Get all module data so we can find dependents and sort.
    $module_data = system_rebuild_module_data();

    // Create an associative array with weights as values.
    $module_list = array_flip(array_values($module_list));
    $profile = drupal_get_profile();
    while (list($module) = each($module_list)) {
      if (!isset($module_data[$module]) || !$module_data[$module]->status) {

        // This module doesn't exist or is already disabled, skip it.
      $module_list[$module] = $module_data[$module]->sort;

      // Add dependent modules to the list, with a placeholder weight.
      // The new modules will be processed as the while loop continues.
      foreach ($module_data[$module]->required_by as $dependent => $dependent_data) {
        if (!isset($module_list[$dependent]) && $dependent != $profile) {
          $module_list[$dependent] = 0;

    // Sort the module list by pre-calculated weights.
    $module_list = array_keys($module_list);
  $invoke_modules = array();
  foreach ($module_list as $module) {
    if (module_exists($module)) {

      // Check if node_access table needs rebuilding.
      if (!node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
      module_invoke($module, 'disable');
        'status' => 0,
        ->condition('type', 'module')
        ->condition('name', $module)
      $invoke_modules[] = $module;
      watchdog('system', '%module module disabled.', array(
        '%module' => $module,
      ), WATCHDOG_INFO);
  if (!empty($invoke_modules)) {

    // Refresh the module list to exclude the disabled modules.
    module_implements('', FALSE, TRUE);

    // Invoke hook_modules_disabled before disabling modules,
    // so we can still call module hooks to get information.
    module_invoke_all('modules_disabled', $invoke_modules);

    // Update the registry to remove the newly-disabled module.

    // Update the theme registry to remove the newly-disabled module.

  // If there remains no more node_access module, rebuilding will be
  // straightforward, we can do it right now.
  if (node_access_needs_rebuild() && count(module_implements('node_grants')) == 0) {


MiSc’s picture

In my installation profile I want to disable the RDF-module, because it do not use it, and it gives me problem when working with features.

Simple straight forward example (from sitexx.profile):

function sitexx_setup_config() {
jnicola’s picture

FYI: This is persistent. Using this function disables the module and it remains disabled per my testing.

Garrett Albright’s picture

You were expecting its effect to be temporary?!

Elijah Lynn’s picture

How would one also uninstall the module?

idebr’s picture

 * Disable and uninstall 'MODULE'.
function MODULE_update_7200() {
  if (module_exists('MODULE')) {
holyfire’s picture

I'd probably recommend doing something like this, we typically will use a standalone module to accomplish this. Not much different from idebr's comment bot for me it's a bit easier to read.

function MODULE_deploy_update_0001() {
  $modules_to_disable = array(
  foreach ($modules_to_disable as $key => $module) {
    if (!module_exists($module)) {
jedihe’s picture

The code snippet above looks quite sub-optimal to me. The loop will run as many times as items in the array, and the whole array will be passed to module_disable() each single time (except when a module is not found, and then unset from the array). So, any given module in that array may be passed to module_disable() as many times as count($modules_to_disable), which isn't needed.

Also, unsetting items from the very array you are using to iterate makes that code a bit difficult to reason about, since I'm not sure how PHP will handle that.

Arnaud Kali’s picture

Actually we don't even need to check for module_exists() here as the function module_disable() already checks for this before disabling the module and would be redundant.

The following should be enough IMO:

function MODULE_update_7001() {
  $modules_to_disable = array(