There is no built-in WordPress function for testing a user’s role, I have to use capability testing via current_user_can()
. You can see it in action in my plugin here.
Since current_user_can()
isn’t meant to test roles, the result is that you can’t really exclude something from the Admin as the admin will always pass the current_user_can('subscriber')
type of tests for lower level roles.
Subscriber can only see things for a subscriber
Editor can see everything a subscriber sees, plus what an editor can see
Admin sees pretty much everything
If you desperately need to hide something from an admin, I would advise creating a new capability and adding it to all the types except admin. The FAQ covers how to add a “pseudo role”. Or you could use a plugin like Members to create an entirely new role with custom caps.