I18N: Make sure wp_dropdown_languages()
does not print out empty name
and id
attributes.
Props johnjamesjacoby, afercia. Fixes #40829. git-svn-id: https://develop.svn.wordpress.org/trunk@41734 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2536a168bb
commit
3447d5e8c6
@ -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'] ) {
|
||||
|
Loading…
Reference in New Issue
Block a user