# Email Alert When Super Admin Rights Change

> Emails the network admin address whenever someone is granted or loses super admin rights, with who made the change.

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

## Code

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

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

$wpide_alert = function ( $user_id, $granted ) use ( $wpide_alert_to ) {
    $user  = get_userdata( $user_id );
    $actor = wp_get_current_user();

    if ( ! $user || ! $wpide_alert_to ) {
        return;
    }

    wp_mail(
        $wpide_alert_to,
        sprintf( '[%s] Super admin %s: %s', get_network()->site_name, $granted ? 'granted' : 'revoked', $user->user_login ),
        sprintf(
            "%1\$s was %2\$s super admin rights by %3\$s on %4\$s.\nIP: %5\$s\n",
            $user->user_login,
            $granted ? 'given' : 'removed from',
            $actor->exists() ? $actor->user_login : 'a system process',
            wp_date( 'Y-m-d H:i' ),
            isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'n/a'
        )
    );
};

add_action( 'granted_super_admin', function ( $user_id ) use ( $wpide_alert ) {
    $wpide_alert( $user_id, true );
} );
add_action( 'revoked_super_admin', function ( $user_id ) use ( $wpide_alert ) {
    $wpide_alert( $user_id, false );
} );
```

## Notes

Change $wpide_alert_to to send the alert somewhere else.

## How to use it

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