Make WordPress Core

Ticket #20810: wp_dropdown_categories_attr_opt.patch

File wp_dropdown_categories_attr_opt.patch, 1.2 KB (added by wpsmith, 13 years ago)

Extra attributes for wp_dropdown_categories()

  • category-template.php

     
    307307                'name' => 'cat', 'id' => '',
    308308                'class' => 'postform', 'depth' => 0,
    309309                'tab_index' => 0, 'taxonomy' => 'category',
    310                 'hide_if_empty' => false
     310                'hide_if_empty' => false,
     311                'attr' => array(),
    311312        );
    312313
    313314        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
     
    325326        }
    326327
    327328        extract( $r );
    328 
    329         $tab_index_attribute = '';
     329       
     330        $attributes = '';
     331        foreach ( (array)$attr as $attr_name => $value ) {
     332                $attributes .= " $attr_name=" . '"' . $value . '"';
     333        }
    330334        if ( (int) $tab_index > 0 )
    331                 $tab_index_attribute = " tabindex=\"$tab_index\"";
    332 
     335                $attributes .= " tabindex=\"$tab_index\"";
     336               
    333337        $categories = get_terms( $taxonomy, $r );
    334338        $name = esc_attr( $name );
    335339        $class = esc_attr( $class );
    336340        $id = $id ? esc_attr( $id ) : $name;
    337341
    338342        if ( ! $r['hide_if_empty'] || ! empty($categories) )
    339                 $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
     343                $output = "<select name='$name' id='$id' class='$class' $attributes>\n";
    340344        else
    341345                $output = '';
    342346