7.x install.inc drupal_uninstall_modules($module_list = array(), $uninstall_dependents = TRUE)

Uninstalls a given list of disabled modules.


string[] $module_list: The modules to uninstall. It is the caller's responsibility to ensure that all modules in this list have already been disabled before this function is called.

bool $uninstall_dependents: (optional) If TRUE, the function will check that all modules which depend on the passed-in module list either are already uninstalled or contained in the list, and it will ensure that the modules are uninstalled 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. Defaults to TRUE.

Return value

bool Returns TRUE if the operation succeeds or FALSE if it aborts due to an unsafe condition, namely, $uninstall_dependents is TRUE and a module in $module_list has dependents which are not already uninstalled and not also included in $module_list).

See also



5 calls to drupal_uninstall_modules()
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.
ModuleUnitTest::testDependencyResolution in modules/simpletest/tests/module.test
Test dependency resolution.
system_modules_uninstall_submit in modules/system/system.admin.inc
Processes the submitted uninstall form.
TaxonomyVocabularyTestCase::testUninstallReinstall in modules/taxonomy/taxonomy.test
Test uninstall and reinstall of the taxonomy module.


includes/install.inc, line 774
API functions for installing modules and themes.


function drupal_uninstall_modules($module_list = array(), $uninstall_dependents = TRUE) {
  if ($uninstall_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]) || drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {

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

      // If the module has any dependents which are not already uninstalled and
      // not included in the passed-in list, abort. It is not safe to uninstall
      // them automatically because uninstalling a module is a destructive
      // operation.
      foreach (array_keys($module_data[$module]->required_by) as $dependent) {
        if (!isset($module_list[$dependent]) && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED && $dependent != $profile) {
          return FALSE;

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

    // Uninstall the module.
    module_invoke($module, 'uninstall');
    watchdog('system', '%module module uninstalled.', array(
      '%module' => $module,
    drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
  if (!empty($module_list)) {

    // Let other modules react.
    module_invoke_all('modules_uninstalled', $module_list);
  return TRUE;


BWPanda’s picture

An obvious statement maybe, but you should run module_disable() first as this function doesn't check that modules are already disabled before uninstalling them...

TravisCarden’s picture

In Drupal 8 this function has been renamed to module_uninstall() (change record).

Garrett Albright’s picture

I've never seen the $uninstall_dependents parameter work as expected. That is, if you want to uninstall "rules" and "rules_admin" and you know that "rules_admin" depends on "rules", just doing drupal_uninstall_modules(array('rules')); will not install both. You have to explicitly list the modules you want uninstalled in the array, as in drupal_uninstall_modules(array('rules_admin', 'rules'));, despite this documentation implying it's not necessary.