# Email Alert When a Network Site Is Deleted

> Sends an email with the site's name, address and the person responsible whenever a site is permanently deleted from the network.

- Type: PHP
- Runs: Run everywhere
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: delete-site, email, audit
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-site-deleted-alert/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

$wpide_alert_to = get_site_option( 'admin_email' ); // Recipient.

add_action( 'wp_uninitialize_site', function ( $site ) use ( $wpide_alert_to ) {
    if ( ! $wpide_alert_to ) {
        return;
    }

    $name  = get_blog_option( $site->blog_id, 'blogname' );
    $actor = wp_get_current_user();

    wp_mail(
        $wpide_alert_to,
        sprintf( '[%s] Site deleted: %s', get_network()->site_name, $name ),
        sprintf(
            "Site: %1\$s\nAddress: %2\$s\nID: %3\$d\nDeleted by: %4\$s\nWhen: %5\$s\n",
            $name,
            $site->domain . $site->path,
            $site->blog_id,
            $actor->exists() ? $actor->user_login : 'system / WP-CLI',
            wp_date( 'Y-m-d H:i' )
        )
    );
}, 1 );
```

## Notes

Sent just before the site's tables are removed, so the site name is still available.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Email Alert When a Network Site 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/
