# Alert the Site Owner When an Administrator's Email or Password Changes

> Emails the site's admin address whenever any administrator account changes its email address or password, a key warning sign of an account takeover.

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

## Code

```php
add_action( 'profile_update', function ( $user_id, $old_data ) {
    $user = get_userdata( $user_id );

    if ( ! $user || ! $old_data || ! user_can( $user, 'manage_options' ) ) {
        return;
    }

    $changes = array();
    if ( $user->user_email !== $old_data->user_email ) {
        $changes[] = sprintf( 'email changed from %s to %s', $old_data->user_email, $user->user_email );
    }
    if ( $user->user_pass !== $old_data->user_pass ) {
        $changes[] = 'password changed';
    }

    if ( ! $changes ) {
        return;
    }

    $actor = wp_get_current_user();
    wp_mail(
        get_option( 'admin_email' ),
        sprintf( '[%s] Administrator account changed', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ),
        sprintf(
            "The administrator account \"%s\" was changed: %s.\n\nChanged by: %s\nIP address: %s\nTime: %s",
            $user->user_login,
            implode( ', ', $changes ),
            $actor->exists() ? $actor->user_login : 'password reset or system',
            isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '',
            wp_date( 'Y-m-d H:i' )
        )
    );
}, 10, 2 );
```

## Notes

WordPress already notifies the affected user; this adds a second notice to the site owner.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Alert the Site Owner When an Administrator's Email or Password Changes" 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/
