Make WordPress Core

Changeset 41734


Ignore:
Timestamp:
10/04/2017 03:22:15 PM (9 years ago)
Author:
SergeyBiryukov
Message:

I18N: Make sure wp_dropdown_languages() does not print out empty name and id attributes.

Props johnjamesjacoby, afercia.
Fixes #40829.

File:
1 edited

Legend:

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

    r41733 r41734  
    11181118 *     Optional. Array or string of arguments for outputting the language selector.
    11191119 *
    1120  *     @type string   $id                           ID attribute of the select element. Default empty.
    1121  *     @type string   $name                         Name attribute of the select element. Default empty.
     1120 *     @type string   $id                           ID attribute of the select element. Default 'locale'.
     1121 *     @type string   $name                         Name attribute of the select element. Default 'locale'.
    11221122 *     @type array    $languages                    List of installed languages, contain only the locales.
    11231123 *                                                  Default empty array.
     
    11351135
    11361136        $parsed_args = wp_parse_args( $args, array(
    1137                 'id'           => '',
    1138                 'name'         => '',
     1137                'id'           => 'locale',
     1138                'name'         => 'locale',
    11391139                'languages'    => array(),
    11401140                'translations' => array(),
     
    11441144                'show_option_site_default'    => false,
    11451145        ) );
     1146
     1147        // Bail if no ID or no name.
     1148        if ( ! $parsed_args['id'] || ! $parsed_args['name'] ) {
     1149                return;
     1150        }
    11461151
    11471152        // English (United States) uses an empty string for the value attribute.
     
    11831188        $translations_available = ( ! empty( $translations ) && $parsed_args['show_available_translations'] );
    11841189
    1185         $output = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) );
    1186 
    11871190        // Holds the HTML markup.
    11881191        $structure = array();
     
    11931196        }
    11941197
     1198        // Site default.
    11951199        if ( $parsed_args['show_option_site_default'] ) {
    11961200                $structure[] = sprintf(
     
    12011205        }
    12021206
     1207        // Always show English.
    12031208        $structure[] = sprintf(
    12041209                '<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
     
    12061211        );
    12071212
     1213        // List installed languages.
    12081214        foreach ( $languages as $language ) {
    12091215                $structure[] = sprintf(
     
    12341240        }
    12351241
     1242        // Combine the output string.
     1243        $output  = sprintf( '<select name="%s" id="%s">', esc_attr( $parsed_args['name'] ), esc_attr( $parsed_args['id'] ) );
    12361244        $output .= join( "\n", $structure );
    1237 
    12381245        $output .= '</select>';
    12391246
Note: See TracChangeset for help on using the changeset viewer.