Only let administrators change a user's email address, so members and customers can't switch their account to a different email.
add_action( 'user_profile_update_errors', function ( WP_Error $errors, bool $update, stdClass $user ): void {
if ( ! $update || current_user_can( 'manage_options' ) ) {
return;
}
$current = get_userdata( $user->ID );
if ( $current && isset( $user->user_email ) && strtolower( $user->user_email ) !== strtolower( $current->user_email ) ) {
$errors->add( 'nahnu_email_locked', 'Please contact us to change your email address.' );
}
}, 10, 3 );
add_action( 'admin_print_footer_scripts-profile.php', function (): void {
if ( current_user_can( 'manage_options' ) ) {
return;
}
echo "<script>document.getElementById( 'email' )?.setAttribute( 'readonly', 'readonly' );</script>";
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
On membership and B2B sites, the email address is often tied to a contract, licence or billing account. Letting users change it themselves can break those links. This snippet locks the field for everyone except administrators.
user_profile_update_errors runs when a profile is saved, before anything is written. If a non-administrator submits a different email, the snippet adds an error and WordPress refuses the save.
A small script also makes the Email field read-only on the profile screen, so people see straight away that they can’t change it.
Log in as a subscriber, open your profile and check the Email field is read-only. Changing it with browser tools and saving should show the error.