# Stop Users From Changing Their Email Address

> Makes the email field read-only for everyone except administrators, for sites where the email is tied to a contract or a login policy.

- Type: PHP
- Runs: Admin only
- 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/lock-email-for-non-admins/

## Code

```php
add_action( 'user_profile_update_errors', function ( $errors, $update, $user ) {
    if ( ! $update || current_user_can( 'manage_options' ) || empty( $user->ID ) ) {
        return;
    }

    $current = get_userdata( $user->ID );

    if ( $current && isset( $user->user_email ) && strtolower( $user->user_email ) !== strtolower( $current->user_email ) ) {
        $user->user_email = $current->user_email;
        $errors->add( 'wpide_email_locked', '<strong>Error:</strong> Your email address can only be changed by an administrator.' );
    }
}, 10, 3 );

add_action( 'admin_footer', function () {
    $screen = get_current_screen();

    if ( ! $screen || 'profile' !== $screen->id || current_user_can( 'manage_options' ) ) {
        return;
    }

    echo '<script>(function(){var f=document.getElementById("email");if(f){f.readOnly=true;f.insertAdjacentHTML("afterend","<p class=\"description\">Contact an administrator to change your email address.</p>");}})();</script>';
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Stop Users From Changing Their Email Address" 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/
