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 {
|
||||
* Optional. Array or string of arguments for outputting the language selector.
|
||||
*
|
||||
* @type string $id ID attribute of the select element. Default empty.
|
||||
* @type string $name Name 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 'locale'.
|
||||
* @type array $languages List of installed languages, contain only the locales.
|
||||
* Default empty array.
|
||||
* @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() ) {
|
||||
|
||||
$parsed_args = wp_parse_args( $args, array(
|
||||
'id' => '',
|
||||
'name' => '',
|
||||
'id' => 'locale',
|
||||
'name' => 'locale',
|
||||
'languages' => array(),
|
||||
'translations' => array(),
|
||||
'selected' => '',
|
||||
|
@ -1144,6 +1144,11 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
'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.
|
||||
if ( 'en_US' === $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'] );
|
||||
|
||||
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) );
|
||||
|
||||
// Holds the HTML markup.
|
||||
$structure = array();
|
||||
|
||||
|
@ -1192,6 +1195,7 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
|
||||
}
|
||||
|
||||
// Site default.
|
||||
if ( $parsed_args['show_option_site_default'] ) {
|
||||
$structure[] = sprintf(
|
||||
'<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(
|
||||
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
|
||||
selected( '', $parsed_args['selected'], false )
|
||||
);
|
||||
|
||||
// List installed languages.
|
||||
foreach ( $languages as $language ) {
|
||||
$structure[] = sprintf(
|
||||
'<option value="%s" lang="%s"%s data-installed="1">%s</option>',
|
||||
|
@ -1233,8 +1239,9 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
$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 .= '</select>';
|
||||
|
||||
if ( $parsed_args['echo'] ) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @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.
|
||||
|
|
Loading…
Reference in New Issue