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.
Built from https://develop.svn.wordpress.org/trunk@37465


git-svn-id: http://core.svn.wordpress.org/trunk@37433 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2016-05-19 02:39:27 +00:00
parent 3b24e53ba7
commit 03fa635ba7
2 changed files with 7 additions and 2 deletions

View File

@ -314,6 +314,7 @@ function category_description( $category = 0 ) {
* *
* @since 2.1.0 * @since 2.1.0
* @since 4.2.0 Introduced the `value_field` argument. * @since 4.2.0 Introduced the `value_field` argument.
* @since 4.6.0 Introduced the `required` argument.
* *
* @param string|array $args { * @param string|array $args {
* Optional. Array or string of arguments to generate a categories drop-down element. * Optional. Array or string of arguments to generate a categories drop-down element.
@ -351,6 +352,8 @@ function category_description( $category = 0 ) {
* @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'. * @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'.
* @type bool $hide_if_empty True to skip generating markup if no categories are found. * @type bool $hide_if_empty True to skip generating markup if no categories are found.
* Default false (create select element even if no categories are found). * Default false (create select element even if no categories are found).
* @type bool $required Whether the <select> element should have the HTML5 'required' attribute.
* Default false.
* } * }
* @return string HTML content only if 'echo' argument is 0. * @return string HTML content only if 'echo' argument is 0.
*/ */
@ -376,6 +379,7 @@ function wp_dropdown_categories( $args = '' ) {
'hide_if_empty' => false, 'hide_if_empty' => false,
'option_none_value' => -1, 'option_none_value' => -1,
'value_field' => 'term_id', 'value_field' => 'term_id',
'required' => false,
); );
$defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
@ -414,9 +418,10 @@ function wp_dropdown_categories( $args = '' ) {
$name = esc_attr( $r['name'] ); $name = esc_attr( $r['name'] );
$class = esc_attr( $r['class'] ); $class = esc_attr( $r['class'] );
$id = $r['id'] ? esc_attr( $r['id'] ) : $name; $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
$required = $r['required'] ? 'required' : '';
if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
$output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; $output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";
} else { } else {
$output = ''; $output = '';
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.6-alpha-37464'; $wp_version = '4.6-alpha-37465';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.