WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress Check User Roles


Here is a plug-n-play function to check user roles, based on an array of input values.

To check whether or not the current user has any of the specified roles, include this function in your plugin or theme’s functions.php file:

Once this function is included, you can call it like so:

Also, if you want to check a specific user ID, you can use the second parameter:

This will check whether or not user with ID 177 has any of the roles, “author”, “editor”, or “custom_role”.

Learn more

WordPress Themes In Depth

Show Support

Like our new Facebook Page to show support!