# get_file_data()

URL: https://chugunov.pro/api-wordpress/functions/get_file_data/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.9.0.

## Сигнатура

```php
get_file_data( string $file, array $default_headers, string $context = '' ): string[]
```

## Описание

Ищет метаданные в первых 8 КБ файла, например плагина или темы.
Каждый фрагмент метаданных должен располагаться на отдельной строке. Поля не могут занимать несколько строк — значение обрезается в конце первой строки.
Если данные файла не помещаются в эти первые 8 КБ, автору следует исправить файл плагина и переместить заголовки данных в начало.

## Параметры

- `$file` `string` — обязательный. Абсолютный путь к файлу.
- `$default_headers` `array` — обязательный. Список заголовков в формате array( 'HeaderKey' => 'Header Name' ).
- `$context` `string` — необязательный, по умолчанию `''`. Если указан, добавляет хук-фильтр 'extra_$context_headers'.

## Возвращаемое значение

`string[]`

## Исходный код

Файл: `wp-includes/functions.php:6946`

```php
function get_file_data( $file, $default_headers, $context = '' ) {
	// Pull only the first 8 KB of the file in.
	$file_data = file_get_contents( $file, false, null, 0, 8 * KB_IN_BYTES );

	if ( false === $file_data ) {
		$file_data = '';
	}

	// Make sure we catch CR-only line endings.
	$file_data = str_replace( "\r", "\n", $file_data );

	/**
	 * Filters extra file headers by context.
	 *
	 * The dynamic portion of the hook name, `$context`, refers to
	 * the context where extra headers might be loaded.
	 *
	 * @since 2.9.0
	 *
	 * @param array $extra_context_headers Empty array by default.
	 */
	$extra_headers = $context ? apply_filters( "extra_{$context}_headers", array() ) : array();
	if ( $extra_headers ) {
		$extra_headers = array_combine( $extra_headers, $extra_headers ); // Keys equal values.
		$all_headers   = array_merge( $extra_headers, (array) $default_headers );
	} else {
		$all_headers = $default_headers;
	}

	foreach ( $all_headers as $field => $regex ) {
		if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
			$all_headers[ $field ] = _cleanup_header_comment( $match[1] );
		} else {
			$all_headers[ $field ] = '';
		}
	}

	return $all_headers;
}
```

## История изменений

- 2.9.0 — Introduced.

## Связанные

Используется в: [`_cleanup_header_comment`](https://chugunov.pro/api-wordpress/functions/_cleanup_header_comment/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), `WP_Theme::get_block_patterns`, `Theme_Upgrader::check_package`, [`get_plugin_data`](https://chugunov.pro/api-wordpress/functions/get_plugin_data/), [`wp_get_pomo_file_data`](https://chugunov.pro/api-wordpress/functions/wp_get_pomo_file_data/), `WP_Theme::__construct`, `WP_Theme`.

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_file_data/
