get_user_locale( int|WP_User $user_id )

Retrieves the locale of a user.


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


Parameters Parameters

$user_id

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


Top ↑

Return Return

(string) The locale of the user.


Top ↑

Source 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

Changelog
Version Description
4.7.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.