wp_dropdown_roles

Advertisement

Summery Summery

Print out option HTML elements for role selectors.

Syntax Syntax

wp_dropdown_roles( string $selected = '' )

Parameters Parameters

$selected

(string) (Optional) Slug for the role that should be already selected.

Default value: ''

Source Source

File: wp-admin/includes/template.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;
}

Advertisement

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.