get_user_locale() WordPress Function

The get_user_locale() function retrieves the locale for a given user. If no user is specified, the current user's locale is retrieved.

get_user_locale( int|WP_User $user_id ) #

Retrieves the locale of a user.


Description

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


Top ↑

Parameters

$user_id

(int|WP_User)(Required)User's ID or a WP_User object. Defaults to current user.


Top ↑

Return

(string) The locale of the user.


Top ↑

Source

File: wp-includes/l10n.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();
}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.