mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-13 00:54:34 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@38955 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user