WordPress at a glance

get_user_locale() WP 1.0

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().

✈ 1 time = 0.00003s = very fast | 50000 times = 0.15s = very fast | PHP 7.0.14, WP 4.7

No Hooks.

Return

String. The locale of the user.

Usage

get_user_locale( $user_id );
$user_id(int/WP_User)
User's ID or a WP_User object.
Default: current user

Code of get_user_locale: wp-includes/l10n.php VER 5.0.1

<?php
function get_user_locale( $user_id = 0 ) {
	$user = false;
	if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
		$user = wp_get_current_user();
	} elseif ( $user_id instanceof WP_User ) {
		$user = $user_id;
	} elseif ( $user_id && is_numeric( $user_id ) ) {
		$user = get_user_by( 'id', $user_id );
	}

	if ( ! $user ) {
		return get_locale();
	}

	$locale = $user->locale;
	return $locale ? $locale : get_locale();
}

Related Functions

From tag: locale (site language)

More from category: Localization

No comments
    Hello, !     Log In . Register