WordPress: Retrieve all roles list

August 25, 2010 | In: php, Wordpress

Many times we need to show all roles in a dropdown for our widget and we try to find in database but we are unable to get correct value.. so here I am providing a good solution to get all list of roles:

<?php 
         global $wp_roles;
       	 $roles = $wp_roles->get_names();
 
         // Below code will print the all list of roles.
         print_r($roles);        
?>