Home / author / List All Available wordpress Roles
  • How to List All Available wordpress Roles

    list-all-available-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,