Make WordPress Core

Ticket #31909: required-wp_dropdown_categories.31909.diff

File required-wp_dropdown_categories.31909.diff, 2.3 KB (added by wzislam, 10 years ago)

I added a patch with HTML5 required attribute

  • src/wp-includes/category-template.php

    diff --git src/wp-includes/category-template.php src/wp-includes/category-template.php
    index 9a2120c..3f6f700 100644
    function category_description( $category = 0 ) { 
    331331 *     @type string       $taxonomy          Name of the category to retrieve. Default 'category'.
    332332 *     @type bool         $hide_if_empty     True to skip generating markup if no categories are found.
    333333 *                                           Default false (create select element even if no categories are found).
     334 *     @type bool|int     $required              Whether the field is required or not using HTML5 'required' attribute.  Accepts 0, 1, or their bool
    334335 * }
    335336 * @return string HTML content only if 'echo' argument is 0.
    336337 */
    337338function wp_dropdown_categories( $args = '' ) {
    338339        $defaults = array(
    339                 'show_option_all' => '', 'show_option_none' => '',
    340                 'orderby' => 'id', 'order' => 'ASC',
     340                'show_option_all' => '',
     341                'show_option_none' => '',
     342                'option_none_value' => -1,
     343                'orderby' => 'id',
     344                'order' => 'ASC',
    341345                'show_count' => 0,
    342                 'hide_empty' => 1, 'child_of' => 0,
    343                 'exclude' => '', 'echo' => 1,
    344                 'selected' => 0, 'hierarchical' => 0,
    345                 'name' => 'cat', 'id' => '',
    346                 'class' => 'postform', 'depth' => 0,
    347                 'tab_index' => 0, 'taxonomy' => 'category',
    348                 'hide_if_empty' => false, 'option_none_value' => -1,
     346                'hide_empty' => 1,
     347                'child_of' => 0,
     348                'exclude' => '',
     349                'echo' => 1,
     350                'selected' => 0,
     351                'hierarchical' => 0,
     352                'name' => 'cat',
     353                'id' => '',
     354                'class' => 'postform',
     355                'depth' => 0,
     356                'tab_index' => 0,
     357                'taxonomy' => 'category',
     358                'hide_if_empty' => false,
    349359                'value_field' => 'term_id',
     360                'required' => false
    350361        );
    351362
    352363        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
    function wp_dropdown_categories( $args = '' ) { 
    379390        $name = esc_attr( $r['name'] );
    380391        $class = esc_attr( $r['class'] );
    381392        $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
     393        $required = $r['required'] ? 'required' : '';
    382394
    383395        if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
    384                 $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
     396                $output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";
    385397        } else {
    386398                $output = '';
    387399        }