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

wp_dropdown_roles

Definition:
function wp_dropdown_roles( $selected = false ) {}

Print out <option> html elements for role selectors

Parameters

  • string $selected: slug for the role that should be already selected

Source code

function wp_dropdown_roles( $selected = false ) {

	$p = '';

	$r = '';



	$editable_roles = get_editable_roles();



	foreach ( $editable_roles as $role => $details ) {

		$name = translate_user_role($details['name'] );

		if ( $selected == $role ) // preselect specified role

			$p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";

		else

			$r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";

	}

	echo $p . $r;

}

3617

wp_dropdown_pages

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

Retrieve or display list of pages as a dropdown (select list).

Parameters

  • array|string $args: Optional. Override default arguments.

Return values

returns:HTML content, if not displaying.

Defined filters

  • wp_dropdown_pages
    apply_filters('wp_dropdown_pages', $output)

Source code

function wp_dropdown_pages($args = '') {

	$defaults = array(

		'depth' => 0, 'child_of' => 0,

		'selected' => 0, 'echo' => 1,

		'name' => 'page_id', 'id' => '',

		'show_option_none' => '', 'show_option_no_change' => '',

		'option_none_value' => ''

	);



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

	extract( $r, EXTR_SKIP );



	$pages = get_pages($r);

	$output = '';

	// Back-compat with old system where both id and name were based on $name argument

	if ( empty($id) )

		$id = $name;



	if ( ! empty($pages) ) {

		$output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n";

		if ( $show_option_no_change )

			$output .= "\t<option value=\"-1\">$show_option_no_change</option>";

		if ( $show_option_none )

			$output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";

		$output .= walk_page_dropdown_tree($pages, $depth, $r);

		$output .= "</select>\n";

	}



	$output = apply_filters('wp_dropdown_pages', $output);



	if ( $echo )

		echo $output;



	return $output;

}

3615

wp_dropdown_cats

Definition:
function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {}

Parameters

  • unknown_type $currentcat
  • unknown_type $currentparent
  • unknown_type $parent
  • unknown_type $level
  • unknown_type $categories

Source code

function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {

	_deprecated_function( __FUNCTION__, '3.0', 'wp_dropdown_categories()' );

	if (!$categories )

		$categories = get_categories( array('hide_empty' => 0) );



	if ( $categories ) {

		foreach ( $categories as $category ) {

			if ( $currentcat != $category->term_id && $parent == $category->parent) {

				$pad = str_repeat( '– ', $level );

				$category->name = esc_html( $category->name );

				echo "\n\t<option value='$category->term_id'";

				if ( $currentparent == $category->term_id )

					echo " selected='selected'";

				echo ">$pad$category->name</option>";

				wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );

			}

		}

	} else {

		return false;

	}

}

3613

wp_dropdown_categories

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

Display or retrieve the HTML dropdown list of categories.
The list of arguments is below: ‘show_option_all’ (string) – Text to display for showing all categories. ‘show_option_none’ (string) – Text to display for showing no categories. ‘orderby’ (string) default is ‘ID’ – What column to use for ordering the categories. ‘order’ (string) default is ‘ASC’ – What direction to order categories. ‘show_last_update’ (bool|int) default is 0 – See get_categories() ‘show_count’ (bool|int) default is 0 – Whether to show how many posts are in the category. ‘hide_empty’ (bool|int) default is 1 – Whether to hide categories that don’t have any posts attached to them. ‘child_of’ (int) default is 0 – See get_categories(). ‘exclude’ (string) – See get_categories(). ‘echo’ (bool|int) default is 1 – Whether to display or retrieve content. ‘depth’ (int) – The max depth. ‘tab_index’ (int) – Tab index for select element. ‘name’ (string) – The name attribute value for select element. ‘id’ (string) – The ID attribute value for select element. Defaults to name if omitted. ‘class’ (string) – The class attribute value for select element. ‘selected’ (int) – Which category ID is selected. ‘taxonomy’ (string) – The name of the taxonomy to retrieve. Defaults to category.

Parameters

  • string|array $args: Optional. Override default arguments.

Return values

returns:HTML content only if ‘echo’ argument is 0.

Defined filters

  • list_cats
    apply_filters( 'list_cats', $show_option_none )
  • list_cats
    apply_filters( 'list_cats', $show_option_all )
  • list_cats
    apply_filters( 'list_cats', $show_option_none )
  • wp_dropdown_cats
    apply_filters( 'wp_dropdown_cats', $output )

Source code

function wp_dropdown_categories( $args = '' ) {

	$defaults = array(

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

		'orderby' => 'id', 'order' => 'ASC',

		'show_last_update' => 0, 'show_count' => 0,

		'hide_empty' => 1, 'child_of' => 0,

		'exclude' => '', 'echo' => 1,

		'selected' => 0, 'hierarchical' => 0,

		'name' => 'cat', 'id' => '',

		'class' => 'postform', 'depth' => 0,

		'tab_index' => 0, 'taxonomy' => 'category',

		'hide_if_empty' => false

	);



	$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;



	// Back compat.

	if ( isset( $args['type'] ) && 'link' == $args['type'] ) {

		_deprecated_argument( __FUNCTION__, '3.0', '' );

		$args['taxonomy'] = 'link_category';

	}



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



	if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {

		$r['pad_counts'] = true;

	}



	$r['include_last_update_time'] = $r['show_last_update'];

	extract( $r );



	$tab_index_attribute = '';

	if ( (int) $tab_index > 0 )

		$tab_index_attribute = " tabindex=\"$tab_index\"";



	$categories = get_terms( $taxonomy, $r );

	$name = esc_attr( $name );

	$class = esc_attr( $class );

	$id = $id ? esc_attr( $id ) : $name;



	if ( ! $r['hide_if_empty'] || ! empty($categories) )

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

	else

		$output = '';



	if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) {

		$show_option_none = apply_filters( 'list_cats', $show_option_none );

		$output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";

	}



	if ( ! empty( $categories ) ) {



		if ( $show_option_all ) {

			$show_option_all = apply_filters( 'list_cats', $show_option_all );

			$selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';

			$output .= "\t<option value='0'$selected>$show_option_all</option>\n";

		}



		if ( $show_option_none ) {

			$show_option_none = apply_filters( 'list_cats', $show_option_none );

			$selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';

			$output .= "\t<option value='-1'$selected>$show_option_none</option>\n";

		}



		if ( $hierarchical )

			$depth = $r['depth'];  // Walk the full depth.

		else

			$depth = -1; // Flat.



		$output .= walk_category_dropdown_tree( $categories, $depth, $r );

	}

	if ( ! $r['hide_if_empty'] || ! empty($categories) )

		$output .= "</select>\n";





	$output = apply_filters( 'wp_dropdown_cats', $output );



	if ( $echo )

		echo $output;



	return $output;

}

3611