Call   0208 3131682   Mon-Fri 9am-6pm

How to get a users Roles and how to list all WordPress roles in PHP

By May 5, 2017 PHP, Programming, Wordpress

This code is handy if you want to find out a users role/s. You could expand it and check if a user has a given role or similar.

This code is based on examples from:

https://codex.wordpress.org/Function_Reference/get_userdata

and

https://wordpress.stackexchange.com/questions/1665/getting-a-list-of-currently-available-roles-on-a-wordpress-site

If you did want to check if the user is in a certain group you could do something like this:

 

One Comment

  • Debbie says:

    Nice! Can you suggest a way to find the highest level role for a single user? Many times users have multiple roles. I am looking to find and return the highest access, such as editor or administrator.

Leave a Reply