Home / author / List All Available wordpress Roles
  • How to 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.

    ( click code to copy )

    wordpress snippet : PHP

    $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>';

    ( WordPress codex functions, hooks, in this snippet. )

    _n, wp,
  • Rafay Aziz

    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