4

I would like to make the email field on the profile page for subscribers read only. They can see their email but not change it. I want only admins to to be able to change users email address.

2 Answers 2

3

Although the readonly attribute can be removed using Chrome/Firebug inspector (making the field editable again), much probably the average user will not know this.

<?php
function wpse50730_script_enqueuer(){
    if(current_user_can('subscriber')) {
        echo '<script type="text/javascript">
        jQuery(document).ready( function($) {
            $(".form-table #email").attr("readonly", true);
        });     
        </script>';
    }
}
add_action('admin_head-profile.php', 'wpse50730_script_enqueuer');
-1

@brasofilo's answer is good, but better use .prop and the .user-email-wrap class to prevent impact on #email fields on other pages.

<script type="text/javascript">
    jQuery(document).ready( function($) {
        $(".user-email-wrap #email").prop('disabled', true);
    });     
</script>
1
  • 1
    @brasofilo's answer only hooks into the profile page and not into others. Every admin screen has a unique hook you can use and that's what you can see in that code. Aug 5, 2016 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.