mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-19 02:34:40 +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:
@@ -351,7 +351,7 @@ final class _WP_Editors {
|
||||
if ( empty( self::$first_init ) ) {
|
||||
self::$baseurl = includes_url( 'js/tinymce' );
|
||||
|
||||
$mce_locale = get_locale();
|
||||
$mce_locale = get_user_locale();
|
||||
self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
|
||||
|
||||
/** This filter is documented in wp-admin/includes/media.php */
|
||||
@@ -672,7 +672,7 @@ final class _WP_Editors {
|
||||
}
|
||||
}
|
||||
|
||||
$body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
|
||||
$body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
|
||||
|
||||
if ( !empty($set['tinymce']['body_class']) ) {
|
||||
$body_class .= ' ' . $set['tinymce']['body_class'];
|
||||
|
||||
@@ -1395,7 +1395,7 @@ final class WP_Theme implements ArrayAccess {
|
||||
* @param array $themes Array of themes to sort, passed by reference.
|
||||
*/
|
||||
public static function sort_by_name( &$themes ) {
|
||||
if ( 0 === strpos( get_locale(), 'en_' ) ) {
|
||||
if ( 0 === strpos( get_user_locale(), 'en_' ) ) {
|
||||
uasort( $themes, array( 'WP_Theme', '_name_sort' ) );
|
||||
} else {
|
||||
uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) );
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
* @property string $display_name
|
||||
* @property string $spam
|
||||
* @property string $deleted
|
||||
* @property string $locale
|
||||
*/
|
||||
class WP_User {
|
||||
/**
|
||||
|
||||
@@ -75,6 +75,23 @@ function get_locale() {
|
||||
return apply_filters( 'locale', $locale );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the locale of the current user.
|
||||
*
|
||||
* If the user has a locale set to a non-empty string then it will be
|
||||
* returned. Otherwise it returns the locale of get_locale().
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @return string The locale of the current user.
|
||||
*/
|
||||
function get_user_locale() {
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$locale = $user->locale;
|
||||
return ( '' === $locale ) ? get_locale() : $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the translation of $text.
|
||||
*
|
||||
@@ -633,7 +650,7 @@ function unload_textdomain( $domain ) {
|
||||
*/
|
||||
function load_default_textdomain( $locale = null ) {
|
||||
if ( null === $locale ) {
|
||||
$locale = get_locale();
|
||||
$locale = is_admin() ? get_user_locale() : get_locale();
|
||||
}
|
||||
|
||||
// Unload previously loaded strings so we can switch translations.
|
||||
@@ -1148,4 +1165,4 @@ function is_rtl() {
|
||||
return false;
|
||||
}
|
||||
return $wp_locale->is_rtl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1358,6 +1358,7 @@ function validate_username( $username ) {
|
||||
* @since 2.0.0
|
||||
* @since 3.6.0 The `aim`, `jabber`, and `yim` fields were removed as default user contact
|
||||
* methods for new installs. See wp_get_user_contact_methods().
|
||||
* @since 4.7.0 The user's locale can be passed to `$userdata`.
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
@@ -1392,6 +1393,7 @@ function validate_username( $username ) {
|
||||
* @type string|bool $show_admin_bar_front Whether to display the Admin Bar for the user on the
|
||||
* site's front end. Default true.
|
||||
* @type string $role User's role.
|
||||
* @type string $locale User's locale. Default empty.
|
||||
* }
|
||||
* @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not
|
||||
* be created.
|
||||
@@ -1606,6 +1608,8 @@ function wp_insert_user( $userdata ) {
|
||||
|
||||
$meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
|
||||
|
||||
$meta['locale'] = isset( $userdata['locale'] ) ? $userdata['locale'] : '';
|
||||
|
||||
$user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login));
|
||||
|
||||
if ( $user_nicename_check ) {
|
||||
@@ -1965,7 +1969,7 @@ function wp_create_user($username, $password, $email = '') {
|
||||
* @return array List of user keys to be populated in wp_update_user().
|
||||
*/
|
||||
function _get_additional_user_keys( $user ) {
|
||||
$keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' );
|
||||
$keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' );
|
||||
return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user