wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_user_locale › WordPress Function

Seit4.7.0
Veraltetn/v
get_user_locale ( $user = 0 )
Parameter:
  • (int|WP_User) $user User's ID or a WP_User object. Defaults to current user.
    Erforderlich: Nein
    Standard:
Gibt zurück:
  • (string) The locale of the user.
Definiert in:
Codex:

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


Quellcode

function get_user_locale( $user = 0 ) {
	$user_object = false;

	if ( 0 === $user && function_exists( 'wp_get_current_user' ) ) {
		$user_object = wp_get_current_user();
	} elseif ( $user instanceof WP_User ) {
		$user_object = $user;
	} elseif ( $user && is_numeric( $user ) ) {
		$user_object = get_user_by( 'id', $user );
	}

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

	$locale = $user_object->locale;

	return $locale ? $locale : get_locale();
}