How to allow an user role to create a new user under a role which lower than his level only?

Posted by Prem Tiwari | Updated on

Firstly, you need to add the following capabilities to the Doctor and Receptionist role:

  • list_users
  • edit_users
  • create_users
  • delete_users

Now we can get to work with controlling which users they can create/edite/delete. Let’s start with a “helper” function that will return which roles a user is allowed to edit:

And to set which roles they can assign a user:

And finally, limit which users they can edit/delete based on their role:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers