# Alert When an Administrator Password Reset Is Requested

> Emails the site admin whenever someone requests a password reset for an administrator account, an early warning sign of an attempt to take over the site.

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

## Code

```php
add_action( 'retrieve_password', function ( $user_login ) {
    $user = get_user_by( 'login', $user_login );

    if ( ! $user || ! user_can( $user, 'manage_options' ) || get_transient( 'wpide_reset_alert_' . $user->ID ) ) {
        return;
    }

    set_transient( 'wpide_reset_alert_' . $user->ID, 1, HOUR_IN_SECONDS );

    $ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : 'unknown';

    wp_mail(
        get_option( 'admin_email' ),
        sprintf( '[%s] Password reset requested for administrator %s', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $user->user_login ),
        sprintf( "A password reset was requested for the administrator account \"%s\" on %s from IP %s.\n\nIf this was not expected, make sure the account's email inbox is secure; the password has not been changed.", $user->user_login, wp_date( 'Y-m-d H:i' ), $ip )
    );
} );
```

## Notes

Sends at most one alert per account per hour; the requester's IP address is included.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Alert When an Administrator Password Reset Is Requested" 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/
