Skip to content

Instantly share code, notes, and snippets.

@hannesl
Created October 10, 2012 09:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hannesl/3864416 to your computer and use it in GitHub Desktop.
Save hannesl/3864416 to your computer and use it in GitHub Desktop.
Delete/cancel a Drupal user programmatically and safely.
// Tell Drupal to cancel this user.
// The third argument can be one of the following:
// - user_cancel_block: disable user, leave content
// - user_cancel_block_unpublish: disable user, unpublish content
// - user_cancel_reassign: delete user, reassign content to uid=0
// - user_cancel_delete: delete user, delete content
user_cancel(array(), $uid, 'user_cancel_reassign');
// user_cancel() initiates a batch process. Run it manually.
$batch =& batch_get();
$batch['progressive'] = FALSE;
batch_process();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment