I wanted to block a bulk amount of users of my site. I was thinking to do it by firing a sql query and turning off the status field of users directory.

So is it safe to fire such sql or is there any otherfunction which does that?

My site is still in drupal 6.

Tks Vil


1 Answer 1


If not Views Bulk Operations as mentioned in the comment above by arpitr there seems to be one function from the core users module which appears to be of the purpose for the same. The User module's hook_user_operations for block operation namely user_user_operations_block would be it to answer your query and should provide you a drupal code way of doing it.

function user_user_operations_block($accounts) {
  foreach ($accounts as $uid) {
    $account = user_load(array('uid' => (int) $uid));
    // Skip blocking user if they are already blocked.
    if ($account !== FALSE && $account->status == 1) {
      user_save($account, array('status' => 0));

Essentially it loads the user account and makes call to user_save with the status as 0. If your implementation is to block users with custom code based on a specific logic, you could do the same or perhaps consider invoking the user module's hook_user_operations for block operation with the desired input though I haven't done something similar. Doing so would prevent you writing your own update query. Hope that helps.

  • I ran the sql query and it works well! for blocking users above 5000 user_load might take some time to load all user details and then it saves it. Firing a sql query works fine as it was just a matter of blocking the users.
    – Villie
    Oct 8, 2013 at 11:48
  • Guess that's the gift and curse of invoking the user hooks, but if they are not required for your operation I guess the straight forward query should be more than adequate, good to know it worked easy that way. Oct 8, 2013 at 12:27

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.