I am trying to give more permissions to the editor role by giving it access to create user accounts. See the code below. But I would like to prevent it from creating or editing existing users with the role of administrator.
function add_theme_caps() {
$role = get_role('editor');
$role->add_cap( 'edit_theme_options' );
$role->add_cap('list_users');
$role->add_cap('create_users');
$role->add_cap('delete_users');
$role->add_cap('edit_users');
}
add_action( 'admin_init', 'add_theme_caps');
Things I am trying to achieve.
- The list_users option lists all the users. I would like to list only the non-admin users.
- I want to limit this role from creating new user accounts with the role of administrator and also prevent it from change the role of any existing users to an administrator.