Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sushyant/f7e3a962a0809ef652eeb702920b15fa to your computer and use it in GitHub Desktop.
Save sushyant/f7e3a962a0809ef652eeb702920b15fa to your computer and use it in GitHub Desktop.
Add this to your theme’s functions.php file. Read more: https://sushyant.com/wordpress/prevent-users-from-changing-email-address
class DisableEmailChange
{
function __construct()
{
add_action('admin_footer', array($this, 'disable_userprofile_fields'));
}
function disable_userprofile_fields()
{
global $pagenow;
if ($pagenow == 'profile.php' && !current_user_can( 'manage_options' )) {
?>
<script>
jQuery(document).ready(function ($) {
if ($('input[name=email]').length) {
$('input[name=email]').attr("disabled", "disabled");
}
});
</script>
<?php
}
}
} // End Class
$DisableEmailChange = new DisableEmailChange();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment