0

I have found out how to disable wordpress admin menu items from users other than administratos. What I would like to achieve now is every user can access only his user page (only "Your profile") and edit only some of the details, for example I don't want the user to change his email but he can change his nickname etc. Is that possible?

0

Add the following, to functions.php of the current theme (child theme is preferred!):

CSS solution:

function no_email_changes_in_profile() {
    $screen = get_current_screen();
    if ('profile' == $screen->base && !current_user_can('manage_options')) {
        echo '<style>
input#email {
    pointer-events: none;
}
</style>';
    }
}
add_action('admin_head', 'no_email_changes_in_profile');

jQuery solution:

function no_email_changes_in_profile() {
    $screen = get_current_screen();
    if ('profile' == $screen->base && !current_user_can('manage_options')) {
        echo "<script>
jQuery(document).ready(function($) {
    $('#email').prop('readonly', true);
});
</script>";
    }
}
add_action('admin_head', 'no_email_changes_in_profile');

This will disable editing of 'Email' field on the profile admin page, for all users, except of an administrator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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