Get current user roles in WordPress

if ( ! function_exists( 'wpcb_get_current_user_roles' ) ) {
    /**
     * Get current user roles.
     *
     * @see    https://wpcodebook.com/snippets/get-current-user-roles-in-wordpress/
     * @return array
     */
    function wpcb_get_current_user_roles() {
        $current_user = wp_get_current_user();
        return $current_user->roles;
    }
}

You can add this snippet to your (child) theme's functions.php file.

No comments yet.

Leave a Reply