$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>restrict admin panel sections to users|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

restrict admin panel sections to users

matteradmin10PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far