Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Disable User Deletion

Security covered Under active development 621 sites

This module provides control over user deletion to prevent accidental data loss or ownership issues. It allows administrators to disable options for deleting a user's content or reassigning it to the anonymous user, thereby safeguarding sensitive production data.

User deletion is always a sensitive task for two key reasons:

  • It can involve the deletion of content or changes to the content's authorization.
  • There are two open core issues: potential content regressions (Issue 3089747) or errors in the ownership of revisions (Issue 2977362).

For these reasons, it is crucial to perform this action in a highly controlled manner.

This module allows you to enable or disable the two actions associated with user deletion:

  • Delete the account and makes its content belong to the Anonymous user.
  • Delete the account and its content.

This helps prevent possible disasters in the production database.

In complex projects, the recommended process is to first test the user deletion in a staging environment. If everything works as expected, you can then proceed with the action in production.

How to configure

  • Go to "/admin/config/disable_user_deletion/settings".
  • Select the actions would you like to disable.

Disable drush commands

To apply these restrictions to Drush commands, copy this code into the file "drush/Commands/PolicyCommands.php":

/**
  * User cancel policy .
  *
  * @hook validate user:cancel
  *
  * @throws \Exception
  */
  public function usercancellValidate(CommandData $commandData) {
    // Only validate if module 'disable_user_deletion' is enabled.
    // @phpstan-ignore-next-line
    if (\Drupal::service('module_handler')->moduleExists('disable_user_deletion')) {
      // @phpstan-ignore-next-line
      $config = \Drupal::config('disable_user_deletion.settings');

      if ($config->get('user_cancel_delete') && $commandData->input()->getOption('delete-content')) {
        throw new \Exception(dt('The option to delete users has been disabled, please contact the technical administrator.'));
      }
      if ($config->get('user_cancel_reassign') && $commandData->input()->getOption('reassign-content')) {
        throw new \Exception(dt('The option to reassign content has been disabled, please contact the technical administrator.'));
      }
        }
}
Drupal 9–11

Ask your assistant about Disable User Deletion

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • user Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
5
Tracked since
Sep 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Release Timeline

Releases

Version Type Core PHP Release date
1.0.1 Stable 9–11 Aug 18, 2025
1.x-dev Dev 9–11 Aug 18, 2025
1.0.0 Stable 9–11 Sep 16, 2024
1.0.0-alpha1 Pre-release 9–11 Sep 12, 2024
1.0.x-dev Dev 9–11 Sep 12, 2024