WordPress – Check user has specific role

Sometimes you need to check WordPress user role to grant permission to access certain area of a WordPress Website. WordPress doesn’t have a function for checking the user role. Following piece of code lets to you check user has specific role in WordPress.

Add following Coding in your theme’s functions.php

You can call it like

The above code return TRUE if the user with ID 10 has the role “author”. Otherwise it return FALSE.

The above code return TRUE if the logged in user has the role “author”. Otherwise it return FALSE.

Following is an example to check the user has specific role.

Following is an example to check the logged in user has specific role.

Hope it helps.

Check WordPress user have specific role
Check WordPress user have role customer, author, editor, subscriber, administrator
wordpress check user role by id
wordpress user_can
wordpress check if user is admin
current_user_can(‘administrator’)
wordpress get_role
check user role in woocommerce
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.