Codex

Plugin API/Action Reference/deleted user

Description

The deleted_user action/hook can be used to perform additional actions after a user is deleted. For example, you can delete rows from custom tables created by a plugin.

The hook passes one parameter: the user's ID.

This hook runs after a user is deleted. The hook delete_user (delete vs deleted) runs before a user is deleted. Choose the appropriate hook for your needs. If you need access to user meta or fields from the user table, use delete_user.

User's deleted from Network Site installs may not trigger this hook. Be sure to use the wpmu_delete_user hook for those cases.

Usage

<?php add_action( 'deleted_user', 'function_name' ); ?>

where "function_name" is the name of the function to be called.

Example: Email Users Being Deleted

Let's have a look at an example:

function my_deleted_user($user_id) {
	global $wpdb;
	$email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE ID = '" . $user_id . "' LIMIT 1");

	 $headers = 'From: ' . get_bloginfo("name") . ' <' . get_bloginfo("admin_email") . '>' . "\r\n";
 	 wp_mail($email, 'You were deleted, brah', 'Your account at ' . get_bloginfo("name") . ' was just deleted.', $headers);
}
add_action( 'deleted_user', 'my_deleted_user');

In this example we send a friendly message to a user after their account has been deleted.

This page is marked as incomplete. You can help Codex by expanding it.