Created
September 13, 2024 02:04
-
-
Save Jerl92/56e9f4da4346b5229982473010dfba84 to your computer and use it in GitHub Desktop.
How to get current user role in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function my_get_current_user_roles() { | |
| if( is_user_logged_in() ) { | |
| $user = wp_get_current_user(); | |
| $roles = ( array ) $user->roles; | |
| return $roles; // This will returns an array | |
| } else { | |
| return array(); | |
| } | |
| } | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://usersinsights.com/wordpress-get-current-user-role/