We use Drupal as an employee portal; as such, when new starters join the business they create an account.

However, we are trying to figure out a good leaving process; right now I get a list and have to manually delete all the users.

Ideally, we would like something which send an email to a user after 14 days and then again after 30 days informing them that they have not logged in into the system; then, after 60 days, they are automatically deleted.

I am guessing that using Rules is the answer, but I cant find any option to delete users.

4 Answers 4


Maybe this module can help: inactive user

From the module page:

After configurable periods of inactivity, one or more of the following actions can be automatically taken:

  • send an email to the user
  • send an email to the site administrator(s)
  • block the account (a warning can first be issued)
  • optionally notify user and/or site administrator(s) that account was blocked
  • delete the account (a warning can first be issued)
  • optionally notify user and/or site administrator(s)1 that account was deleted

If the Rules module doesn't have a predefined action that allows deleting a user, then you can choose the action that executes the code necessary to find the users that didn't log in the past 90 days, and deletes them.

You can create a rule that is executed when Cron maintenance tasks are performed (that is one of the events you can select when creating a rule), and add an "Execute custom PHP code" action.

$query = db_query_range("SELECT uid FROM {users} WHERE access < %d", time() - 7776000, 0, 20);

while ($uid = db_result($query)) {
  user_delete(array(), $uid);

return array();

The result would be something similar to the following one:


The return statement is probably not necessary, but as I understand, the Rules module is expecting the code returns an array containing something that needs to be saved; the code could return a node that needs to be saved, for example, and which will be saved if the node has been modified.
The 7776000 value I used is the number of seconds in 90 days.

This is the solution I would adopt if you are already using the Rules module. If you are going to install it just to be able to accomplish this task, then it would be better to use a custom module that implements hook_cron(), or using a module that already does the task.
Which one to choose depends from what you plan to do with the module you are going to install; if you are using few of the module's features, then a custom module is probably a better solution.

  • Looks really good however the inactive user module seems to cater for my requirement pretty much perfectly. Going to give that a go first.
    – WestieUK
    Commented Aug 3, 2011 at 15:22

I also use Views Bulk Operations for this. I set up a query that does what I want, and then execute the "delete user" action. Before doing that, I do a "send email" action to tell them why they're being deleted.


Been in search how to complete similar task. Found an answer @Drupal.org - if your Rules don't have 'Delete user' option then you have to install Views Bulk Operations module - it provides such operation (and lots of others :) Of course, it can be done with custom PHP code in different ways, but this solution is useful if your site has disabled PHP input for security reasons (and you don't want to write the action by yourself).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.