Ticket #24731: multiple-select.patch
File multiple-select.patch, 2.8 KB (added by , 11 years ago) |
---|
-
wp-includes/category-template.php
307 307 'name' => 'cat', 'id' => '', 308 308 'class' => 'postform', 'depth' => 0, 309 309 'tab_index' => 0, 'taxonomy' => 'category', 310 'hide_if_empty' => false 310 'hide_if_empty' => false, 311 'multiple' => false 311 312 ); 312 313 313 314 $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; … … 324 325 $r['pad_counts'] = true; 325 326 } 326 327 328 // make sure selected is always an array 329 if ( !is_array( $r['selected'] ) ) { 330 $r['selected'] = array($r['selected']); 331 } 332 327 333 extract( $r ); 328 334 329 335 $tab_index_attribute = ''; 330 336 if ( (int) $tab_index > 0 ) 331 337 $tab_index_attribute = " tabindex=\"$tab_index\""; 332 338 339 $multiple_attribute = ''; 340 if ( $r['multiple'] ) { 341 $multiple_attribute = 'multiple'; 342 343 // if this isn't a multiple select, make sure only one value is selected 344 } else { 345 $r['selected'] = array_slice( $r['selected'], 0, 1 ); 346 } 347 333 348 $categories = get_terms( $taxonomy, $r ); 334 349 $name = esc_attr( $name ); 335 350 $class = esc_attr( $class ); 336 351 $id = $id ? esc_attr( $id ) : $name; 337 352 338 353 if ( ! $r['hide_if_empty'] || ! empty($categories) ) 339 $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";354 $output = "<select $multiple_attribute name='$name' id='$id' class='$class' $tab_index_attribute>\n"; 340 355 else 341 356 $output = ''; 342 357 … … 349 364 350 365 if ( $show_option_all ) { 351 366 $show_option_all = apply_filters( 'list_cats', $show_option_all ); 352 $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';367 $selected = ( in_array( '0', $r['selected'], true) ) ? " selected='selected'" : ''; 353 368 $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; 354 369 } 355 370 356 371 if ( $show_option_none ) { 357 372 $show_option_none = apply_filters( 'list_cats', $show_option_none ); 358 $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : '';373 $selected = ( in_array( '-1', $r['selected'], true) ) ? " selected='selected'" : ''; 359 374 $output .= "\t<option value='-1'$selected>$show_option_none</option>\n"; 360 375 } 361 376 … … 370 385 if ( ! $r['hide_if_empty'] || ! empty($categories) ) 371 386 $output .= "</select>\n"; 372 387 373 $output = apply_filters( 'wp_dropdown_cats', $output );388 $output = apply_filters( 'wp_dropdown_cats', $output, $r ); 374 389 375 390 if ( $echo ) 376 391 echo $output; … … 938 953 939 954 $cat_name = apply_filters('list_cats', $category->name, $category); 940 955 $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\""; 941 if ( $category->term_id == $args['selected'])956 if ( in_array( $category->term_id, $args['selected'] ) ) 942 957 $output .= ' selected="selected"'; 943 958 $output .= '>'; 944 959 $output .= $pad.$cat_name;