Do you want to display a list of all available WordPress role names? This snippet displays a select list of all available WordPress role names.
Instructions
All you have to do is add this code to your theme wherever you would like to display a select list of available WordPress role names.
$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>';
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you want to change the capabilities of a role, check out this snippet: How To Change User Role Capabilities.
If you liked this code snippet, please consider checking out How to Create a Custom User Registration Form in WordPress.
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