Advertisements

wp_dropdown_users

Definition:
function wp_dropdown_users( $args = '' ) {}

Create dropdown HTML content of users.
The content can either be displayed, which it is by default or retrieved by setting the ‘echo’ argument. The ‘include’ and ‘exclude’ arguments do not need to be used; all users will be displayed in that case. Only one can be used, either ‘include’ or ‘exclude’, but not both.

Parameters

  • string|array $args: Optional. Override defaults.

Return values

returns:Null on display. String of HTML content on retrieve.

Source code

function wp_dropdown_users( $args = '' ) {

	$defaults = array(

		'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',

		'orderby' => 'display_name', 'order' => 'ASC',

		'include' => '', 'exclude' => '', 'multi' => 0,

		'show' => 'display_name', 'echo' => 1,

		'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',

		'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false

	);



	$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;



	$r = wp_parse_args( $args, $defaults );

	extract( $r, EXTR_SKIP );



	$query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );

	$query_args['fields'] = array( 'ID', $show );

	$users = get_users( $query_args );



	$output = '';

	if ( !empty($users) && ( empty($hide_if_only_one_author) || count($users) > 1 ) ) {

		$name = esc_attr( $name );

		if ( $multi && ! $id )

			$id = '';

		else

			$id = $id ? " id='" . esc_attr( $id ) . "'" : " id='$name'";



		$output = "<select name='{$name}'{$id} class='$class'>\n";

3619

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: