wp_dropdown_roles

Print out option html elements for role selectors.

Description

wp_dropdown_roles( (string) $selected = '' ); 

Parameters (1)

0. $selected — Optional. (string) => ''
Slug for the role that should be already selected.

Usage

  1. if ( !function_exists( 'wp_dropdown_roles' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Slug for the role that should be already selected. 
  5. $selected = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_dropdown_roles($selected); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function wp_dropdown_roles( $selected = '' ) { 
  2. $p = ''; 
  3. $r = ''; 
  4.  
  5. $editable_roles = array_reverse( get_editable_roles() ); 
  6.  
  7. foreach ( $editable_roles as $role => $details ) { 
  8. $name = translate_user_role($details['name'] ); 
  9. if ( $selected == $role ) // preselect specified role 
  10. $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; 
  11. else 
  12. $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>"; 
  13. echo $p . $r;