# Email the Admin When Users Change Their Profile

> Sends the site admin a short email listing what changed when a member updates their own name, email, website or bio.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, profile, email
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/notify-admin-profile-changes/

## Code

```php
// Fields to watch: user field or meta key => label.
$wpide_watch_fields = array(
    'user_email'   => 'Email',
    'display_name' => 'Display name',
    'user_url'     => 'Website',
    'first_name'   => 'First name',
    'last_name'    => 'Last name',
    'description'  => 'Biographical info',
);

$wpide_profile_before = array();

// Capture the old values before the update is written.
add_filter( 'wp_pre_insert_user_data', function ( $data, $update, $user_id ) use ( $wpide_watch_fields, &$wpide_profile_before ) {
    if ( $update && $user_id && get_current_user_id() === (int) $user_id && ! current_user_can( 'edit_users' ) ) {
        $user = get_userdata( $user_id );

        foreach ( array_keys( $wpide_watch_fields ) as $field ) {
            $wpide_profile_before[ $user_id ][ $field ] = (string) $user->get( $field );
        }
    }

    return $data;
}, 10, 3 );

add_action( 'profile_update', function ( $user_id ) use ( $wpide_watch_fields, &$wpide_profile_before ) {
    if ( empty( $wpide_profile_before[ $user_id ] ) ) {
        return;
    }

    clean_user_cache( $user_id );
    $user    = get_userdata( $user_id );
    $changes = array();

    foreach ( $wpide_watch_fields as $field => $label ) {
        $old = $wpide_profile_before[ $user_id ][ $field ];
        $new = (string) $user->get( $field );

        if ( $old !== $new ) {
            $changes[] = sprintf( "%s: \"%s\" -> \"%s\"", $label, $old, $new );
        }
    }

    unset( $wpide_profile_before[ $user_id ] );

    if ( $changes ) {
        wp_mail(
            get_option( 'admin_email' ),
            sprintf( '[%s] %s updated their profile', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $user->user_login ),
            implode( "\n", $changes ) . "\n\n" . admin_url( 'user-edit.php?user_id=' . $user_id )
        );
    }
}, 20 );
```

## Notes

Only changes users make to their own account are reported; edits by administrators are ignored.

## How to use it

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