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(&$form, &$form_state, $form_id) {
$form['#submit'][] = 'MYMODULE_user_cancel_form_submit';
}
function MYMODULE_user_cancel_form_submit(&$form, &$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') && empty($form_state['values']['user_cancel_confirm']) && $account->uid != $user->uid) {
// Account has already been cancelled by the system.
}
else {
// Cancel the account
user_cancel($form_state['values'], $account->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.