Make WordPress Core


Ignore:
Timestamp:
11/08/2016 11:00:38 PM (8 years ago)
Author:
swissspidy
Message:

I18N: Add ability to change user's locale back to site's locale.

Previously there was no way to remove the user locale setting again, even though that might be desirable.

This adds a new 'Site Default' option to the user-specific language setting by introducing a new show_site_locale_default argument to wp_dropdown_languages().

Props ocean90.
See #29783.
Fixes #38632.

File:
1 edited

Legend:

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

    r39134 r39169  
    10491049 * @since 4.0.0
    10501050 * @since 4.3.0 Introduced the `echo` argument.
     1051 * @since 4.7.0 Introduced the `show_site_locale_default` argument.
    10511052 *
    10521053 * @see get_available_languages()
     
    10661067 *                                                  boolean equivalents. Default 1.
    10671068 *     @type bool     $show_available_translations  Whether to show available translations. Default true.
     1069 *     @type bool     $show_site_locale_default     Whether to show an option to fall back to the site's locale. Default false.
    10681070 * }
    10691071 * @return string HTML content
     
    10791081        'echo'         => 1,
    10801082        'show_available_translations' => true,
     1083        'show_site_locale_default'    => false,
    10811084    ) );
     1085
     1086    // English (United States) uses an empty string for the value attribute.
     1087    if ( 'en_US' === $args['selected'] ) {
     1088        $args['selected'] = '';
     1089    }
    10821090
    10831091    $translations = $args['translations'];
     
    11231131        $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
    11241132    }
    1125     $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>';
     1133
     1134    if ( $args['show_site_locale_default'] ) {
     1135        $structure[] = sprintf(
     1136            '<option value="site-default" data-installed="1"%s>%s</option>',
     1137            selected( 'site-default', $args['selected'], false ),
     1138            _x( 'Site Default', 'default site language' )
     1139        );
     1140    }
     1141
     1142    $structure[] = sprintf(
     1143        '<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
     1144        selected( '', $args['selected'], false )
     1145    );
     1146
    11261147    foreach ( $languages as $language ) {
    11271148        $structure[] = sprintf(
Note: See TracChangeset for help on using the changeset viewer.