Title: wp_dropdown_roles
Published: April 25, 2014
Last modified: May 20, 2026

---

# wp_dropdown_roles( string $selected = '', array $editable_roles = null )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#wp--skip-link--target)

Prints out option HTML elements for role selectors.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#parameters)󠁿

 `$selected`stringoptional

Slug for the role that should be already selected.

Default:`''`

`$editable_roles`arrayoptional

Array of roles to include in the dropdown. Defaults to all roles the current user
is allowed to edit.

Default:`null`

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#source)󠁿

    ```php
    function wp_dropdown_roles( $selected = '', $editable_roles = null ) {
    	$r = '';

    	if ( null === $editable_roles ) {
    		$editable_roles = array_reverse( get_editable_roles() );
    	}

    	foreach ( $editable_roles as $role => $details ) {
    		$name = translate_user_role( $details['name'] );
    		// Preselect specified role.
    		if ( $selected === $role ) {
    			$r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>";
    		} else {
    			$r .= "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>";
    		}
    	}

    	echo $r;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/template.php#L976)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/template.php#L976-L994)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#related)󠁿

| Uses | Description | 
| [get_editable_roles()](https://developer.wordpress.org/reference/functions/get_editable_roles/)`wp-admin/includes/user.php` |

Fetch a filtered list of user roles that the current user is allowed to edit.

  | 
| [translate_user_role()](https://developer.wordpress.org/reference/functions/translate_user_role/)`wp-includes/l10n.php` |

Translates role name.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#)

| Used by | Description | 
| [WP_Users_List_Table::extra_tablenav()](https://developer.wordpress.org/reference/classes/wp_users_list_table/extra_tablenav/)`wp-admin/includes/class-wp-users-list-table.php` |

Outputs the controls to allow user roles to be changed in bulk.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Added $editable_roles parameter. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/?output_format=md#comment-content-1430)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_dropdown_roles/#comment-1430)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_roles%2F%23comment-1430)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_roles%2F%23comment-1430)
 4. **Example**
 5. If you would like to set a default role for the dropdown, provide the slug for 
    the desired role as a parameter. The following example creates a dropdown of user
    roles with the “Editor” role as the default, selected value:
 6.     ```php
        <select>
           <?php wp_dropdown_roles( 'editor' ); ?>
        </select>
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_roles%2F%3Freplytocom%3D1430%23feedback-editor-1430)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_dropdown_roles%2F)
before being able to contribute a note or feedback.