# Email Alert When a User Account Is Deleted

> Emails the site admin when any user account is deleted, including who deleted it and whether their content was reassigned, so removals never go unnoticed.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, alerts, users
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-alert-user-deleted/

## Code

```php
add_action( 'delete_user', function ( $user_id, $reassign = null ) {
    $user  = get_userdata( $user_id );
    $actor = wp_get_current_user();

    if ( ! $user ) {
        return;
    }

    $reassigned = $reassign ? get_userdata( (int) $reassign ) : false;

    wp_mail(
        get_option( 'admin_email' ),
        sprintf( '[%s] User deleted: %s', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $user->user_login ),
        sprintf(
            "The account %s <%s> (%s) was deleted by %s on %s.\nContent: %s",
            $user->user_login,
            $user->user_email,
            implode( ', ', (array) $user->roles ),
            $actor->exists() ? $actor->user_login : 'an automated process',
            wp_date( 'Y-m-d H:i' ),
            $reassigned ? 'reassigned to ' . $reassigned->user_login : 'deleted with the account'
        )
    );
}, 10, 2 );
```

## Notes

Works for single sites; on multisite network user deletions use a different hook.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Email Alert When a User Account Is Deleted" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
