WP_Locale_Switcher::filter_locale() WordPress Method

The WP_Locale_Switcher::filter_locale() method is used to filter the locale used by WordPress. The method takes two parameters: the currentlocale and an array of allowedlocales. The currentlocale is the locale that WordPress is currently using, while the allowedlocales is an array of all the locales that are allowed by the site administrator. If the currentlocale is not allowed, the method will try to find a allowedlocale that is close to the currentlocale. For example, if the currentlocale is 'en-US' and the allowedlocales is ['en-GB', 'de-DE', 'es-ES'], the method will try to find 'en-GB' first. If it can't find 'en-GB', it will try to find 'de-DE'. If it can't find 'de-DE', it will try to find 'es-ES'.

WP_Locale_Switcher::filter_locale( string $locale ) #

Filters the locale of the WordPress installation.


Parameters

$locale

(string)(Required)The locale of the WordPress installation.


Top ↑

Return

(string) The locale currently being switched to.


Top ↑

Source

File: wp-includes/class-wp-locale-switcher.php

	public function filter_locale( $locale ) {
		$switched_locale = end( $this->locales );

		if ( $switched_locale ) {
			return $switched_locale;
		}

		return $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.