WordPress: How to get role name of a user by id

{$wpdb->prefix . 'capabilities'};
        if (count($capabilities) > 0) :
	    if ( !isset( $wp_roles ) )
	   	    $wp_roles = new WP_Roles();

	    foreach ( $wp_roles->role_names as $role => $name ) :
		    if ( array_key_exists( $role, $capabilities ) )
			    echo $role;
	    endforeach;
        endif;
?>

This code will print the role name of the user whose id is store in $user_id variable.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*