*/ /** * Implementation of hook_perm(). */ function user_delete_perm() { return array('delete own account'); } /** * Implementation of hook_menu(). */ function user_delete_menu($may_cache) { global $user; $items = array(); if (!$may_cache) { $items[] = array( 'path' => 'user/'. arg(1) .'/delete', 'title' => t('Delete'), 'callback' => 'user_edit', 'access' => (user_access('administer users') || (user_access('delete own account') && arg(1) == $user->uid)), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/user/user_delete', 'title' => t('User delete'), 'description' => t("Configure the user delete action."), 'callback' => 'drupal_get_form', 'callback arguments' => 'user_delete_settings', 'access' => user_access('administer users'), ); } return $items; } /** * Implementation of hook_form_alter(). */ function user_delete_form_alter($form_id, &$form) { global $user; if($form_id == 'user_edit') { //access check if(user_access('delete own account') && arg(1) == $user->uid) { $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), '#weight' => 31, ); } } } /** * Administrative settings page * * @return array * a form array */ function user_delete_settings() { //TODO: add additional settings based on http://drupal.org/node/8#comment-628434 $form['user_delete_redirect'] = array( '#type' => 'textfield', '#title' => t('Redirection page'), '#default_value' => variable_get('user_delete_redirect', ''), '#description' => t('Choose where to redirect your users after account deletion. Any valid Drupal path will do, e.g. %front or %node', array('%front' => '', '%node' => 'node/1')), '#required' => TRUE, ); return system_settings_form($form); } /** * Implementation of hook_user(). */ function user_delete_user($op, &$edit, &$account, $category = NULL) { global $user; //Note: $account->uid and $user->uid are still available! if ($op == 'delete' && ($account->uid == $user->uid)) { //TODO: add additional actions based on http://drupal.org/node/8#comment-628434 //Imitate default behaviour //Assign all nodes and comments to anonymous db_query("UPDATE {node} SET uid=0 WHERE uid=%d", $account->uid); db_query("UPDATE {comments} SET uid=0 WHERE uid=%d", $account->uid); //Redirect drupal_goto(variable_get('user_delete_redirect', '')); } }