0

I want editors to be able to list, add and edit users. I thought the following code would do it, but it doesn't work - no new User menu appears for any editors. Have I missed something?

function increase_editor_role(){
    $role = get_role('editor');
    $role->add_cap('list_users'); 
    $role->add_cap('edit_users'); 
    $role->add_cap('create_users'); 
}
add_action('admin_init', 'increase_editor_role');
1

I believe your code is right. Try going to: 'wp-admin/users.php' manually to check if you have the privilege to do so. If my inkling is right, it's just the $submenu item that is hidden.

If you can access the list of users, try printing the global variable $submenu and see if 'users.php' is there.

  • Thank you. There was an unset() elsewhere in the code! – user417627 May 2 '14 at 8:34
1

The code looks like it should work.

One thing to take in mind is when you run that code it will write to the database. Because of that an editor will not have those privileges on the next page load, it will be the page load after that it takes effect.

With that in mind also - you might want to wrap it in a conditional so it only runs once and not every time the admin area is hit as writes to the database will slow your site down. Either that or if you do get it working, remove the code.

I also agree with some of the other comments that this could be something that a plugin can do for you due to the fact that it's driven from the database.

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.