How can I allow users to cancel their accounts without requiring e-mail confirmation? In Drupal 7, users can cancel their accounts from the account settings page.  However, by default this requires e-mail confirmation.

There is an option "Require e-mail verification when a visitor creates an account" but no option "Do not require e-mail verification when a user cancels an account."

Is there some way to allow users to simply cancel their accounts while logged in rather than requiring them to verify the cancellation via e-mail?
The behaviour seems to be hard-coded into the user_cancel_confirm_form_submit(), which sends a message to the user if they don't have the administer users permission.

I can't see any pretty way of getting round it really, but there is something you can do.

First you need to set an undocumented variable called user_mail_cancel_confirm_notify to FALSE. I'd recommend using Drush to do it:

drush vset user_mail_cancel_confirm_notify FALSE


But you can do it in PHP if you need to:

variable_set('user_mail_cancel_confirm_notify', FALSE);


That will stop the _user_mail_notify() function from sending the cancellation confirmation email.

Next, you need to hook into the form submission for the cancellation confirm form, and force-cancel the account (otherwise it would be waiting for the user to click the cancellation link in the email you've just stopped):

function MYMODULE_form_user_cancel_confirm_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['#submit'][] = 'MYMODULE_user_cancel_form_submit';
}

function MYMODULE_user_cancel_form_submit(&amp;$form, &amp;$form_state) {
  // Rather than negating the complex access expression from the original form we can
  // just make the change in the else portion

  global $user;
  $account = $form_state['values']['_account'];
  if (user_access('administer users') &amp;&amp; empty($form_state['values']['user_cancel_confirm']) &amp;&amp; $account-&gt;uid != $user-&gt;uid) {
    // Account has already been cancelled by the system.
  }
  else {
    // Cancel the account
    user_cancel($form_state['values'], $account-&gt;uid, $form_state['values']['user_cancel_method']);
  }
}


I haven't tested any of that but after reading the functions involved in the user module I'm pretty sure it will work.