From 49c5fb895dbb0685b6fe153b7b89fe937a2067b8 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 26 Oct 2016 14:15:32 +0000 Subject: [PATCH] I18N: Add `$user_id` argument to `get_user_locale()`. This allows to retrieve the locale of any user with the additional fallback to the site locale. Fixes #38512. See #29783, #26511. Built from https://develop.svn.wordpress.org/trunk@38955 git-svn-id: http://core.svn.wordpress.org/trunk@38898 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/l10n.php | 22 +++++++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 03a7a11bec..ba696ded93 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -76,20 +76,32 @@ function get_locale() { } /** - * Retrieves the locale of the current user. + * Retrieves the locale of a 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. + * @param int|WP_User $user_id User's ID or a WP_User object. Defaults to current user. + * @return string The locale of the user. */ -function get_user_locale() { - $user = wp_get_current_user(); +function get_user_locale( $user_id = 0 ) { + $user = false; + if ( 0 === $user_id ) { + $user = wp_get_current_user(); + } elseif ( $user_id instanceof WP_User ) { + $user = $user_id; + } elseif ( is_numeric( $user_id ) ) { + $user = get_user_by( 'id', $user_id ); + } + + if ( ! $user ) { + return get_locale(); + } $locale = $user->locale; - return ( '' === $locale ) ? get_locale() : $locale; + return $locale ? $locale : get_locale(); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index b4709fa781..16ce9cd87c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38954'; +$wp_version = '4.7-alpha-38955'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.