WP_Textdomain_Registry::get_path_from_lang_dir()privateWP 6.1.0

Gets the path to the language directory for the current locale.

Checks the plugins and themes language directories as well as any custom directory set via load_plugin_textdomain() or load_theme_textdomain().

Метод класса: WP_Textdomain_Registry{}

Хуков нет.

Возвращает

Строку|false. Language directory path or false if there is none available.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_path_from_lang_dir( $domain, $locale );
$domain(строка) (обязательный)
Text domain.
$locale(строка) (обязательный)
Locale.

Заметки

Список изменений

С версии 6.1.0 Введена.

Код WP_Textdomain_Registry::get_path_from_lang_dir() WP 6.1.1

private function get_path_from_lang_dir( $domain, $locale ) {
	$locations = array(
		WP_LANG_DIR . '/plugins',
		WP_LANG_DIR . '/themes',
	);

	if ( isset( $this->custom_paths[ $domain ] ) ) {
		$locations[] = $this->custom_paths[ $domain ];
	}

	$mofile = "$domain-$locale.mo";

	foreach ( $locations as $location ) {
		if ( ! isset( $this->cached_mo_files[ $location ] ) ) {
			$this->set_cached_mo_files( $location );
		}

		$path = $location . '/' . $mofile;

		if ( in_array( $path, $this->cached_mo_files[ $location ], true ) ) {
			$this->set( $domain, $locale, $location );

			return trailingslashit( $location );
		}
	}

	// If no path is found for the given locale and a custom path has been set
	// using load_plugin_textdomain/load_theme_textdomain, use that one.
	if ( 'en_US' !== $locale && isset( $this->custom_paths[ $domain ] ) ) {
		$path = trailingslashit( $this->custom_paths[ $domain ] );
		$this->set( $domain, $locale, $path );
		return $path;
	}

	$this->set( $domain, $locale, false );

	return false;
}