Make WordPress Core


Ignore:
Timestamp:
05/19/2016 02:38:33 AM (9 years ago)
Author:
boonebgorges
Message:

Introduce required argument for wp_dropdown_categories().

This allows the HTML5 required attribute to be added to the select element.

Props wzislam, pcarvalho.
Fixes #31909.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/category-template.php

    r37463 r37465  
    315315 * @since 2.1.0
    316316 * @since 4.2.0 Introduced the `value_field` argument.
     317 * @since 4.6.0 Introduced the `required` argument.
    317318 *
    318319 * @param string|array $args {
     
    352353 *     @type bool         $hide_if_empty     True to skip generating markup if no categories are found.
    353354 *                                           Default false (create select element even if no categories are found).
     355 *     @type bool         $required          Whether the <select> element should have the HTML5 'required' attribute.
     356 *                                           Default false.
    354357 * }
    355358 * @return string HTML content only if 'echo' argument is 0.
     
    377380        'option_none_value' => -1,
    378381        'value_field'       => 'term_id',
     382        'required'          => false,
    379383    );
    380384
     
    415419    $class = esc_attr( $r['class'] );
    416420    $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
     421    $required = $r['required'] ? 'required' : '';
    417422
    418423    if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
    419         $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
     424        $output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";
    420425    } else {
    421426        $output = '';
Note: See TracChangeset for help on using the changeset viewer.