function hook_user_cancel

Act on user account cancellations.

This hook is invoked from user_cancel() before a user account is canceled. Depending on the account cancellation method, the module should either do nothing, unpublish content, or anonymize content. See user_cancel_methods() for the list of default account cancellation methods provided by User module. Modules may add further methods via hook_user_cancel_methods_alter().

This hook is NOT invoked for the 'user_cancel_delete' account cancellation method. To react to that method, implement hook_user_predelete() or hook_user_delete() instead.

Expensive operations should be added to the global account cancellation batch by using batch_set().

Parameters

$edit: The array of form values submitted by the user.

$account: The user object on which the operation is being performed.

$method: The account cancellation method.

See also

user_cancel_methods()

hook_user_cancel_methods_alter()

Related topics

5 functions implement hook_user_cancel()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_user_cancel in drupal/core/modules/comment/comment.module
Implements hook_user_cancel().
history_user_cancel in drupal/core/modules/history/history.module
Implements hook_user_cancel().
node_user_cancel in drupal/core/modules/node/node.module
Implements hook_user_cancel().
poll_user_cancel in drupal/core/modules/poll/poll.module
Implements hook_user_cancel().
statistics_user_cancel in drupal/core/modules/statistics/statistics.module
Implements hook_user_cancel().
1 invocation of hook_user_cancel()
user_cancel in drupal/core/modules/user/user.module
Cancel a user account.

File

drupal/core/modules/user/user.api.php, line 102
Hooks provided by the User module.

Code

function hook_user_cancel($edit, $account, $method) {
  switch ($method) {
    case 'user_cancel_block_unpublish':

      // Unpublish nodes (current revisions).
      module_load_include('inc', 'node', 'node.admin');
      $nodes = db_select('node', 'n')
        ->fields('n', array(
        'nid',
      ))
        ->condition('uid', $account->uid)
        ->execute()
        ->fetchCol();
      node_mass_update($nodes, array(
        'status' => 0,
      ));
      break;
    case 'user_cancel_reassign':

      // Anonymize nodes (current revisions).
      module_load_include('inc', 'node', 'node.admin');
      $nodes = db_select('node', 'n')
        ->fields('n', array(
        'nid',
      ))
        ->condition('uid', $account->uid)
        ->execute()
        ->fetchCol();
      node_mass_update($nodes, array(
        'uid' => 0,
      ));

      // Anonymize old revisions.
      db_update('node_revision')
        ->fields(array(
        'uid' => 0,
      ))
        ->condition('uid', $account->uid)
        ->execute();
      break;
  }
}