admin管理员组文章数量:1130349
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.
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.
本文标签: restrict admin panel sections to users
版权声明:本文标题:restrict admin panel sections to users 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749080714a2313007.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论