WP_Textdomain_Registry::get_language_files_from_path()publicWP 6.5.0

Retrieves translation files from the specified path.

Allows early retrieval through the {@see 'pre_get_mo_files_from_path'} filter to optimize performance, especially in directories with many files.

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

Хуки из метода

Возвращает

Массив. Array of translation file paths. Can contain .mo and .l10n.php files.

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

$WP_Textdomain_Registry = new WP_Textdomain_Registry();
$WP_Textdomain_Registry->get_language_files_from_path( $path );
$path(строка) (обязательный)
The directory path to search for translation files.

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

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

Код WP_Textdomain_Registry::get_language_files_from_path() WP 6.7.1

public function get_language_files_from_path( $path ) {
	$path = rtrim( $path, '/' ) . '/';

	/**
	 * Filters the translation files retrieved from a specified path before the actual lookup.
	 *
	 * Returning a non-null value from the filter will effectively short-circuit
	 * the MO files lookup, returning that value instead.
	 *
	 * This can be useful in situations where the directory contains a large number of files
	 * and the default glob() function becomes expensive in terms of performance.
	 *
	 * @since 6.5.0
	 *
	 * @param null|array $files List of translation files. Default null.
	 * @param string     $path  The path from which translation files are being fetched.
	 */
	$files = apply_filters( 'pre_get_language_files_from_path', null, $path );

	if ( null !== $files ) {
		return $files;
	}

	$cache_key = md5( $path );
	$files     = wp_cache_get( $cache_key, 'translation_files' );

	if ( false === $files ) {
		$files = glob( $path . '*.mo' );
		if ( false === $files ) {
			$files = array();
		}

		$php_files = glob( $path . '*.l10n.php' );
		if ( is_array( $php_files ) ) {
			$files = array_merge( $files, $php_files );
		}

		wp_cache_set( $cache_key, $files, 'translation_files', HOUR_IN_SECONDS );
	}

	return $files;
}