WordPress at a glance

wp_dropdown_roles() WP 1.0

Print out option html elements for role selectors.

Works based on: get_editable_roles()

No Hooks.

Return

Nothing (null).

Usage

wp_dropdown_roles( $selected );
$selected(string)
Slug for the role that should be already selected.
Default: ''

Code of wp_dropdown_roles: wp-admin/includes/template.php VER 4.9.8

<?php
function wp_dropdown_roles( $selected = '' ) {
	$r = '';

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

Related Functions

From tag: _dropdown (select options list)

More from category: Other

No comments
    Hello, !     Log In . Register