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?
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?
Share Improve this question asked Dec 3, 2018 at 8:31 dvn22dvn22 13 bronze badges1 Answer
Reset to default 0Add 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.