I18N: Make sure `wp_dropdown_languages()` does not print out empty `name` and `id` attributes.
Props johnjamesjacoby, afercia. Fixes #40829. Built from https://develop.svn.wordpress.org/trunk@41734 git-svn-id: http://core.svn.wordpress.org/trunk@41568 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
35617e12dd
commit
54ff178923
|
@ -1117,8 +1117,8 @@ function wp_get_pomo_file_data( $po_file ) {
|
||||||
* @param string|array $args {
|
* @param string|array $args {
|
||||||
* Optional. Array or string of arguments for outputting the language selector.
|
* Optional. Array or string of arguments for outputting the language selector.
|
||||||
*
|
*
|
||||||
* @type string $id ID attribute of the select element. Default empty.
|
* @type string $id ID attribute of the select element. Default 'locale'.
|
||||||
* @type string $name Name attribute of the select element. Default empty.
|
* @type string $name Name attribute of the select element. Default 'locale'.
|
||||||
* @type array $languages List of installed languages, contain only the locales.
|
* @type array $languages List of installed languages, contain only the locales.
|
||||||
* Default empty array.
|
* Default empty array.
|
||||||
* @type array $translations List of available translations. Default result of
|
* @type array $translations List of available translations. Default result of
|
||||||
|
@ -1134,8 +1134,8 @@ function wp_get_pomo_file_data( $po_file ) {
|
||||||
function wp_dropdown_languages( $args = array() ) {
|
function wp_dropdown_languages( $args = array() ) {
|
||||||
|
|
||||||
$parsed_args = wp_parse_args( $args, array(
|
$parsed_args = wp_parse_args( $args, array(
|
||||||
'id' => '',
|
'id' => 'locale',
|
||||||
'name' => '',
|
'name' => 'locale',
|
||||||
'languages' => array(),
|
'languages' => array(),
|
||||||
'translations' => array(),
|
'translations' => array(),
|
||||||
'selected' => '',
|
'selected' => '',
|
||||||
|
@ -1144,6 +1144,11 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
'show_option_site_default' => false,
|
'show_option_site_default' => false,
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
// Bail if no ID or no name.
|
||||||
|
if ( ! $parsed_args['id'] || ! $parsed_args['name'] ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// English (United States) uses an empty string for the value attribute.
|
// English (United States) uses an empty string for the value attribute.
|
||||||
if ( 'en_US' === $parsed_args['selected'] ) {
|
if ( 'en_US' === $parsed_args['selected'] ) {
|
||||||
$parsed_args['selected'] = '';
|
$parsed_args['selected'] = '';
|
||||||
|
@ -1182,8 +1187,6 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
|
|
||||||
$translations_available = ( ! empty( $translations ) && $parsed_args['show_available_translations'] );
|
$translations_available = ( ! empty( $translations ) && $parsed_args['show_available_translations'] );
|
||||||
|
|
||||||
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) );
|
|
||||||
|
|
||||||
// Holds the HTML markup.
|
// Holds the HTML markup.
|
||||||
$structure = array();
|
$structure = array();
|
||||||
|
|
||||||
|
@ -1192,6 +1195,7 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
|
$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Site default.
|
||||||
if ( $parsed_args['show_option_site_default'] ) {
|
if ( $parsed_args['show_option_site_default'] ) {
|
||||||
$structure[] = sprintf(
|
$structure[] = sprintf(
|
||||||
'<option value="site-default" data-installed="1"%s>%s</option>',
|
'<option value="site-default" data-installed="1"%s>%s</option>',
|
||||||
|
@ -1200,11 +1204,13 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always show English.
|
||||||
$structure[] = sprintf(
|
$structure[] = sprintf(
|
||||||
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
|
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
|
||||||
selected( '', $parsed_args['selected'], false )
|
selected( '', $parsed_args['selected'], false )
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// List installed languages.
|
||||||
foreach ( $languages as $language ) {
|
foreach ( $languages as $language ) {
|
||||||
$structure[] = sprintf(
|
$structure[] = sprintf(
|
||||||
'<option value="%s" lang="%s"%s data-installed="1">%s</option>',
|
'<option value="%s" lang="%s"%s data-installed="1">%s</option>',
|
||||||
|
@ -1233,8 +1239,9 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
$structure[] = '</optgroup>';
|
$structure[] = '</optgroup>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Combine the output string.
|
||||||
|
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) );
|
||||||
$output .= join( "\n", $structure );
|
$output .= join( "\n", $structure );
|
||||||
|
|
||||||
$output .= '</select>';
|
$output .= '</select>';
|
||||||
|
|
||||||
if ( $parsed_args['echo'] ) {
|
if ( $parsed_args['echo'] ) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9-alpha-41733';
|
$wp_version = '4.9-alpha-41734';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
Loading…
Reference in New Issue