wp_dropdown_pages() allows option_none_value to be passed. Add that arg to the $defaults for wp_dropdown_users() and wp_dropdown_categories() as well.

Props solarissmoke. 
Fixes #16625.

Built from https://develop.svn.wordpress.org/trunk@28564


git-svn-id: http://core.svn.wordpress.org/trunk@28390 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-05-23 20:47:15 +00:00
parent b75c79500b
commit 53ea68e838
2 changed files with 10 additions and 7 deletions

View File

@ -331,7 +331,7 @@ function wp_dropdown_categories( $args = '' ) {
'name' => 'cat', 'id' => '',
'class' => 'postform', 'depth' => 0,
'tab_index' => 0, 'taxonomy' => 'category',
'hide_if_empty' => false
'hide_if_empty' => false, 'option_none_value' => -1
);
$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
@ -343,6 +343,7 @@ function wp_dropdown_categories( $args = '' ) {
}
$r = wp_parse_args( $args, $defaults );
$option_none_value = $r['option_none_value'];
if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
$r['pad_counts'] = true;
@ -381,7 +382,7 @@ function wp_dropdown_categories( $args = '' ) {
* @param string $element Taxonomy element to list.
*/
$show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
$output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n";
}
if ( ! empty( $categories ) ) {
@ -398,8 +399,8 @@ function wp_dropdown_categories( $args = '' ) {
/** This filter is documented in wp-includes/category-template.php */
$show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
$selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';
$output .= "\t<option value='-1'$selected>$show_option_none</option>\n";
$selected = selected( $option_none_value, $r['selected'], false );
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n";
}
if ( $r['hierarchical'] ) {

View File

@ -1285,7 +1285,8 @@ function wp_dropdown_users( $args = '' ) {
'include' => '', 'exclude' => '', 'multi' => 0,
'show' => 'display_name', 'echo' => 1,
'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false
'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false,
'option_none_value' => -1
);
$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
@ -1294,6 +1295,7 @@ function wp_dropdown_users( $args = '' ) {
$show = $r['show'];
$show_option_all = $r['show_option_all'];
$show_option_none = $r['show_option_none'];
$option_none_value = $r['option_none_value'];
$query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
$query_args['fields'] = array( 'ID', 'user_login', $show );
@ -1314,8 +1316,8 @@ function wp_dropdown_users( $args = '' ) {
}
if ( $show_option_none ) {
$_selected = selected( -1, $r['selected'], false );
$output .= "\t<option value='-1'$_selected>$show_option_none</option>\n";
$_selected = selected( $option_none_value, $r['selected'], false );
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
}
$found_selected = false;