This plugin automatically deletes users that have not logged in for a configurable number of days.
Automatically deleting users is useful to keep your database clean and remove old accounts that are no longer needed. The plugin can be configured to send warning emails a number of days before the user is deleted. This gives users the chance to log back in and keep their accounts active. It furthermore supports deleting users in a GDPR-compliant way, leaving no trace of personally identifiable information (PII) inside the user record.
The automatic user deletion plugin plugin is available via the Moodle plugin directory:
- Automatically deleting inactive user accounts
- Sending warning emails to users before deletion
- GDPR-compliant deletion of user accounts
- Ignoring users with specific roles
- Dry-run mode for testing the configuration
- Highly configurable (deletion and warning thresholds, email templates, enabling/disabling of single features, etc.)
- Logging of deletion events
- Automated testing and support for all active Moodle releases
The plugin can be configured via the Moodle site administration under Site administration > Plugins > Admin tools > Automatic user deletion.
After installation, the plugin will be disabled by default until you configure and enable it by checking the Enable plugin checkbox (1) and saving the settings.
If the plugin is enabled as described above, users that have not logged in for at least the configured number of days will be deleted automatically. You can configure the number of days of inactivity via the Deletion threshold setting (1).
The plugin also supports sending users an email right before their account is deleted. This is useful to give users a final notice that their account is now deleted. You can enable sending such deletion notifications to users by checking the Deletion notifications checkbox and optionally adjust the email sent (2). If you wish to send users a warning message a few days before their actual deletion to allow them to log back in and keep their account, please refer to account deletion warnings below.
Warning emails can be sent a number of days before the user is deleted. This informs users that their account will be deleted soon and gives them time to perform a login to keep their account active.
To enable this feature, check the Deletion warnings checkbox (1) and set Warning threshold (2) to the number of days before the Deletion threshold when the warning email should be sent. You can also customize the email sent to users (3) if desired.
Note on the warning threshold: The warning threshold is the number of days before the deletion threshold that a warning email is sent. So, for example, if you set your deletion threshold to 1095 days and your warning threshold to 30 days, users will receive a warning email after 1065 days of inactivity. If they do not log in within the next 30 days, their account will be deleted after the full 1095 days of inactivity. If, however, users log back in within the 30 days, their account will be kept until it has been inactive for another 1095 days, receiving a warning email again after 1065 days of inactivity.
When deleting a user, Moodle retains some parts of the user record inside the database by design. This includes first name, last name, e-mail address, last IP address, and other sensitive information. This may be a concern, depending on the specific data privacy policies of your organization or local legal interpretations.
This plugin supports anonymizing the remaining user data when deleting a user. This means that all personally identifiable information (PII) is removed from the database and replaced with generic data. For example, the firstname and lastname are replaced with "DELETED" and their last IP address is replaced with "0.0.0.0".
To enable this feature, check the Anonymize deleted users checkbox (1) inside the plugin settings within the User deletion section.
The plugin supports excluding users based on their role assignments. This means that a user that has a specific role assigned to them will never be deleted nor receive any inactivity warning mails. Note that global site admins are always excluded from deletion.
To exclude users with specific roles, mark the desired role in the Ignored roles selector (1) and save your changes.
If you have configured the plugin to your liking, you can see which users would be affected by your current configuration by using the dry-run feature. You can perform a dry-run by clicking the Perform dry-run button on the plugin settings page.
This will take you to a page that shows you all users that would be warned or deleted, based on your current configuration.
By default, all users are checked for inactivity once per day. You can change the check frequency and time by using the Configure check interval button on the plugin settings page.
The plugin logs all actions it performs. Every time a warning e-mail is sent, a user is finally deleted, or a user was marked as recovered after a previously sent warning e-mail, an entry in this action log is created. User inactivity checks that did not perform any actions are not logged.
You can inspect the action log by clicking the View action log button on the plugin settings page.
This will take you to a page that shows you all performed actions in a sortable table. If no actions have been performed yet, only an informational message will be displayed.
You can use the View raw scheduled task logs button at the bottom of the page to quickly access the raw logs of the scheduled task within the Moodle website administration for debugging purposes.
This plugin can be installed like any other Moodle plugin by placing its source code inside your Moodle installation and executing the upgrade routine afterward.
-
Download the latest release of this plugin from the Moodle plugin directory.
-
Log in to your Moodle site as an admin and go to Site administration > Plugins > Install plugins.
-
Upload the ZIP file with the plugin code.
-
Check the plugin validation report and finish the installation.
The plugin can be also installed by putting the contents of this directory into
{your/moodle/dirroot}/admin/tool/userautodelete
Afterwards, log in to your Moodle site as an admin and go to Site administration > Notifications to complete the installation.
Alternatively, you can run php admin/cli/upgrade.php from the command line to complete the installation.
If you find a bug or have a feature request, please open an issue via the GitHub issue tracker.
Please do not use the comments section within the Moodle plugin directory. Thanks :)
You can find testing instructions for developers in the TESTING.md file.
2025 Niels Gandraß [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.










