mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-09 07:04:34 +00:00
I18N: Introduce a user-specific language setting.
By enabling the user to select their preferred locale when editing the profile, we allow for greater personalization of the WordPress admin and therefore a better user experience. The back end will be displayed in the user's individual locale while the locale used on the front end equals the one set for the whole site. If the user didn't specify a locale, the site's locale will be used as a fallback. The new `locale` property of the `WP_User` class can be used to retrieve the user's locale setting. Props ocean90, ipm-frommen, swissspidy. Fixes #29783. git-svn-id: https://develop.svn.wordpress.org/trunk@38705 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -156,7 +156,7 @@ if ( $current_screen->taxonomy )
|
||||
$admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( get_bloginfo( 'version' ) ) );
|
||||
$admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', get_bloginfo( 'version' ) ) );
|
||||
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
|
||||
|
||||
if ( wp_is_mobile() )
|
||||
$admin_body_class .= ' mobile';
|
||||
|
||||
@@ -134,7 +134,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
|
||||
'active_installs' => true
|
||||
),
|
||||
// Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
|
||||
'locale' => get_locale(),
|
||||
'locale' => get_user_locale(),
|
||||
'installed_plugins' => $this->get_installed_plugin_slugs(),
|
||||
);
|
||||
|
||||
|
||||
@@ -1312,7 +1312,7 @@ class WP_Press_This {
|
||||
$admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( $wp_version ) );
|
||||
$admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) );
|
||||
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
|
||||
|
||||
/** This filter is documented in wp-admin/admin-header.php */
|
||||
$admin_body_classes = apply_filters( 'admin_body_class', '' );
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
function wp_credits() {
|
||||
$wp_version = get_bloginfo( 'version' );
|
||||
$locale = get_locale();
|
||||
$locale = get_user_locale();
|
||||
|
||||
$results = get_site_transient( 'wordpress_credits_' . $locale );
|
||||
|
||||
|
||||
@@ -1353,7 +1353,7 @@ function wp_dashboard_browser_nag() {
|
||||
$notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
|
||||
|
||||
$browsehappy = 'http://browsehappy.com/';
|
||||
$locale = get_locale();
|
||||
$locale = get_user_locale();
|
||||
if ( 'en_US' !== $locale )
|
||||
$browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
|
||||
|
||||
|
||||
@@ -125,13 +125,13 @@ function wp_import_handle_upload() {
|
||||
function wp_get_popular_importers() {
|
||||
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
|
||||
|
||||
$locale = get_locale();
|
||||
$locale = get_user_locale();
|
||||
$cache_key = 'popular_importers_' . md5( $locale . $wp_version );
|
||||
$popular_importers = get_site_transient( $cache_key );
|
||||
|
||||
if ( ! $popular_importers ) {
|
||||
$url = add_query_arg( array(
|
||||
'locale' => get_locale(),
|
||||
'locale' => get_user_locale(),
|
||||
'version' => $wp_version,
|
||||
), 'http://api.wordpress.org/core/importers/1.1/' );
|
||||
$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() );
|
||||
|
||||
@@ -109,7 +109,7 @@ function plugins_api( $action, $args = array() ) {
|
||||
}
|
||||
|
||||
if ( ! isset( $args->locale ) ) {
|
||||
$args->locale = get_locale();
|
||||
$args->locale = get_user_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1622,7 +1622,7 @@ do_action( "admin_head-$hook_suffix" );
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_head' );
|
||||
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
|
||||
|
||||
if ( is_rtl() )
|
||||
$admin_body_class .= ' rtl';
|
||||
|
||||
@@ -412,7 +412,7 @@ function themes_api( $action, $args = array() ) {
|
||||
}
|
||||
|
||||
if ( ! isset( $args->locale ) ) {
|
||||
$args->locale = get_locale();
|
||||
$args->locale = get_user_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,6 +94,16 @@ function edit_user( $user_id = 0 ) {
|
||||
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' == $_POST['rich_editing'] ? 'false' : 'true';
|
||||
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
|
||||
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
|
||||
$user->locale = '';
|
||||
|
||||
if ( isset( $_POST['locale'] ) ) {
|
||||
$locale = sanitize_text_field( $_POST['locale'] );
|
||||
if ( ! in_array( $locale, get_available_languages(), true ) ) {
|
||||
$locale = '';
|
||||
}
|
||||
|
||||
$user->locale = ( '' === $locale ) ? 'en_US' : $locale;
|
||||
}
|
||||
}
|
||||
|
||||
$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';
|
||||
|
||||
@@ -209,19 +209,23 @@ if ( 'update' == $action ) {
|
||||
$value = null;
|
||||
if ( isset( $_POST[ $option ] ) ) {
|
||||
$value = $_POST[ $option ];
|
||||
if ( ! is_array( $value ) )
|
||||
if ( ! is_array( $value ) ) {
|
||||
$value = trim( $value );
|
||||
}
|
||||
$value = wp_unslash( $value );
|
||||
}
|
||||
update_option( $option, $value );
|
||||
}
|
||||
|
||||
// Switch translation in case WPLANG was changed.
|
||||
$language = get_option( 'WPLANG' );
|
||||
if ( $language ) {
|
||||
load_default_textdomain( $language );
|
||||
} else {
|
||||
unload_textdomain( 'default' );
|
||||
$language = get_option( 'WPLANG' );
|
||||
$user_language = get_user_locale();
|
||||
if ( $language === $user_language ) {
|
||||
if ( $language ) {
|
||||
load_default_textdomain( $language );
|
||||
} else {
|
||||
unload_textdomain( 'default' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ foreach ( $plugin_files as $plugin_file ) :
|
||||
<input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
|
||||
</div>
|
||||
<?php if ( !empty( $docs_select ) ) : ?>
|
||||
<div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&redirect=true'); }" /></div>
|
||||
<div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&redirect=true'); }" /></div>
|
||||
<?php endif; ?>
|
||||
<?php if ( is_writeable($real_file) ) : ?>
|
||||
<?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
|
||||
|
||||
@@ -263,7 +263,7 @@ else : ?>
|
||||
<div id="documentation" class="hide-if-no-js">
|
||||
<label for="docs-list"><?php _e('Documentation:') ?></label>
|
||||
<?php echo $docs_select; ?>
|
||||
<input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&redirect=true'); }" />
|
||||
<input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&redirect=true'); }" />
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
@@ -269,6 +269,38 @@ if ( !( IS_PROFILE_PAGE && !$user_can_edit ) ) : ?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$languages = get_available_languages();
|
||||
if ( $languages ) : ?>
|
||||
<tr class="user-language-wrap">
|
||||
<th scope="row">
|
||||
<label for="site_language"><?php _e( 'Site Language' ); ?></label>
|
||||
</th>
|
||||
<td>
|
||||
<?php
|
||||
$user_locale = get_user_option( 'locale', $profileuser->ID );
|
||||
|
||||
if ( 'en_US' === $user_locale ) { // en_US
|
||||
$user_locale = false;
|
||||
} elseif ( ! in_array( $user_locale, $languages, true ) ) {
|
||||
$user_locale = get_locale();
|
||||
}
|
||||
|
||||
wp_dropdown_languages( array(
|
||||
'name' => 'locale',
|
||||
'id' => 'locale',
|
||||
'selected' => $user_locale,
|
||||
'languages' => $languages,
|
||||
'show_available_translations' => false
|
||||
) );
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Fires at the end of the 'Personal Options' settings table on the user editing screen.
|
||||
|
||||
Reference in New Issue
Block a user