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. Built from https://develop.svn.wordpress.org/trunk@39169 git-svn-id: http://core.svn.wordpress.org/trunk@39109 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2f7f8d526b
commit
548ac82b06
|
@ -98,11 +98,13 @@ function edit_user( $user_id = 0 ) {
|
|||
|
||||
if ( isset( $_POST['locale'] ) ) {
|
||||
$locale = sanitize_text_field( $_POST['locale'] );
|
||||
if ( ! in_array( $locale, get_available_languages(), true ) ) {
|
||||
if ( 'site-default' === $locale ) {
|
||||
$locale = '';
|
||||
} elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
|
||||
$locale = 'en_US';
|
||||
}
|
||||
|
||||
$user->locale = ( '' === $locale ) ? 'en_US' : $locale;
|
||||
$user->locale = $locale;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -284,9 +284,9 @@ if ( $languages ) : ?>
|
|||
$user_locale = $profileuser->locale;
|
||||
|
||||
if ( 'en_US' === $user_locale ) {
|
||||
$user_locale = false;
|
||||
} elseif ( ! in_array( $user_locale, $languages, true ) ) {
|
||||
$user_locale = get_locale();
|
||||
$user_locale = '';
|
||||
} elseif ( '' === $user_locale || ! in_array( $user_locale, $languages, true ) ) {
|
||||
$user_locale = 'site-default';
|
||||
}
|
||||
|
||||
wp_dropdown_languages( array(
|
||||
|
@ -294,7 +294,8 @@ if ( $languages ) : ?>
|
|||
'id' => 'locale',
|
||||
'selected' => $user_locale,
|
||||
'languages' => $languages,
|
||||
'show_available_translations' => false
|
||||
'show_available_translations' => false,
|
||||
'show_site_locale_default' => true
|
||||
) );
|
||||
?>
|
||||
</td>
|
||||
|
|
|
@ -1048,6 +1048,7 @@ function wp_get_pomo_file_data( $po_file ) {
|
|||
*
|
||||
* @since 4.0.0
|
||||
* @since 4.3.0 Introduced the `echo` argument.
|
||||
* @since 4.7.0 Introduced the `show_site_locale_default` argument.
|
||||
*
|
||||
* @see get_available_languages()
|
||||
* @see wp_get_available_translations()
|
||||
|
@ -1065,6 +1066,7 @@ function wp_get_pomo_file_data( $po_file ) {
|
|||
* @type bool|int $echo Whether to echo the generated markup. Accepts 0, 1, or their
|
||||
* boolean equivalents. Default 1.
|
||||
* @type bool $show_available_translations Whether to show available translations. Default true.
|
||||
* @type bool $show_site_locale_default Whether to show an option to fall back to the site's locale. Default false.
|
||||
* }
|
||||
* @return string HTML content
|
||||
*/
|
||||
|
@ -1078,8 +1080,14 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
'selected' => '',
|
||||
'echo' => 1,
|
||||
'show_available_translations' => true,
|
||||
'show_site_locale_default' => false,
|
||||
) );
|
||||
|
||||
// English (United States) uses an empty string for the value attribute.
|
||||
if ( 'en_US' === $args['selected'] ) {
|
||||
$args['selected'] = '';
|
||||
}
|
||||
|
||||
$translations = $args['translations'];
|
||||
if ( empty( $translations ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
|
||||
|
@ -1122,7 +1130,20 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
if ( $translations_available ) {
|
||||
$structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
|
||||
}
|
||||
$structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>';
|
||||
|
||||
if ( $args['show_site_locale_default'] ) {
|
||||
$structure[] = sprintf(
|
||||
'<option value="site-default" data-installed="1"%s>%s</option>',
|
||||
selected( 'site-default', $args['selected'], false ),
|
||||
_x( 'Site Default', 'default site language' )
|
||||
);
|
||||
}
|
||||
|
||||
$structure[] = sprintf(
|
||||
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
|
||||
selected( '', $args['selected'], false )
|
||||
);
|
||||
|
||||
foreach ( $languages as $language ) {
|
||||
$structure[] = sprintf(
|
||||
'<option value="%s" lang="%s"%s data-installed="1">%s</option>',
|
||||
|
|
|
@ -1074,7 +1074,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'locale' => array(
|
||||
'description' => __( 'Locale for the resource.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_merge( array( 'en_US' ), get_available_languages() ),
|
||||
'enum' => array_merge( array( '', 'en_US' ), get_available_languages() ),
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'nickname' => array(
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.7-beta2-39168';
|
||||
$wp_version = '4.7-beta2-39169';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue