X

List All Available wordpress Roles

Here is a snippet showing how to list all available roles. I recently used this snippet to add a role selector in the registration page. You could also use it for user searches, or post filters.

$roles_obj = new WP_Roles();
$roles_names_array = $roles_obj->get_names();
echo '<select name="role">';
foreach ($roles_names_array as $role_name) {
	echo '<option>'.$role_name.'</option>';
}
echo '</select>';

Comments  Leave a Reply

  1. Hi i put this snippet in my wordpress function.php file it does work but what is actually does that it shows continuously the list even after logged in on the top left corner
    How can i show it just in the registration form and no where else
    and one more thing it is showing the administrator option as well can we edit options to custom list which we want our user to sign up
    and one more thing i want to make a user which can sell its product on my website but have just access to only his page and cannot touch any other user’s products at the back end please suggest me how can i do that without multi sites can we just define user to access specific pages which can only be accessed by admin and the user created it not by any other user

    Thanks And regards

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!