# Email Alert When Key Site Settings Change

> Emails the site admin when important settings change, such as the site address, admin email, open registration or the default role for new users, a common sign of a hacked site.

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

## Code

```php
// Option name => label.
$wpide_watched_options = array(
    'siteurl'           => 'WordPress address',
    'home'              => 'Site address',
    'admin_email'       => 'Admin email',
    'users_can_register' => 'Anyone can register',
    'default_role'      => 'New user default role',
    'blog_public'       => 'Search engine visibility',
);

add_action( 'updated_option', function ( $option, $old, $new ) use ( $wpide_watched_options ) {
    if ( ! isset( $wpide_watched_options[ $option ] ) || $old === $new ) {
        return;
    }

    $user = wp_get_current_user();
    $to   = 'admin_email' === $option ? array_filter( array( (string) $old, (string) $new ), 'is_email' ) : get_option( 'admin_email' );

    wp_mail(
        $to,
        sprintf( '[%s] Setting changed: %s', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $wpide_watched_options[ $option ] ),
        sprintf(
            "\"%s\" was changed by %s on %s.\n\nOld value: %s\nNew value: %s",
            $wpide_watched_options[ $option ],
            $user->exists() ? $user->user_login : 'an automated process or WP-CLI',
            wp_date( 'Y-m-d H:i' ),
            is_scalar( $old ) ? (string) $old : wp_json_encode( $old ),
            is_scalar( $new ) ? (string) $new : wp_json_encode( $new )
        )
    );
}, 10, 3 );
```

## Notes

Edit the watched options at the top; each change is reported with the old and new value and the user who made it.

## How to use it

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