# wp_print_theme_file_tree()

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

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

## Сигнатура

```php
wp_print_theme_file_tree( array|string $tree, int $level = 2, int $size = 1, int $index = 1 )
```

## Описание

Выводит отформатированный список файлов для редактора файлов темы.

## Параметры

- `$tree` `array|string` — обязательный. Список путей к файлам/папкам или имя файла.
- `$level` `int` — необязательный, по умолчанию `2`. Значение aria-level для текущей итерации.
- `$size` `int` — необязательный, по умолчанию `1`. Значение aria-setsize для текущей итерации.
- `$index` `int` — необязательный, по умолчанию `1`. Значение aria-posinset для текущей итерации.

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

Файл: `wp-admin/includes/misc.php:399`

```php
function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) {
	global $relative_file, $stylesheet;

	if ( is_array( $tree ) ) {
		$index = 0;
		$size  = count( $tree );

		foreach ( $tree as $label => $theme_file ) :
			++$index;

			if ( ! is_array( $theme_file ) ) {
				wp_print_theme_file_tree( $theme_file, $level, $index, $size );
				continue;
			}
			?>
			<li role="treeitem" aria-expanded="true" tabindex="-1"
				aria-level="<?php echo esc_attr( $level ); ?>"
				aria-setsize="<?php echo esc_attr( $size ); ?>"
				aria-posinset="<?php echo esc_attr( $index ); ?>">
				<span class="folder-label"><?php echo esc_html( $label ); ?> <span class="screen-reader-text">
					<?php
					/* translators: Hidden accessibility text. */
					_e( 'folder' );
					?>
				</span><span aria-hidden="true" class="icon"></span></span>
				<ul role="group" class="tree-folder"><?php wp_print_theme_file_tree( $theme_file, $level + 1, $index, $size ); ?></ul>
			</li>
			<?php
		endforeach;
	} else {
		$filename = $tree;
		$url      = add_query_arg(
			array(
				'file'  => rawurlencode( $tree ),
				'theme' => rawurlencode( $stylesheet ),
			),
			self_admin_url( 'theme-editor.php' )
		);
		?>
		<li role="none" class="<?php echo esc_attr( $relative_file === $filename ? 'current-file' : '' ); ?>">
			<a role="treeitem" tabindex="<?php echo esc_attr( $relative_file === $filename ? '0' : '-1' ); ?>"
				href="<?php echo esc_url( $url ); ?>"
				aria-level="<?php echo esc_attr( $level ); ?>"
				aria-setsize="<?php echo esc_attr( $size ); ?>"
				aria-posinset="<?php echo esc_attr( $index ); ?>">
				<?php
				$file_description = esc_html( get_file_description( $filename ) );

				if ( $file_description !== $filename && wp_basename( $filename ) !== $file_description ) {
					$file_description .= '<br /><span class="nonessential">(' . esc_html( $filename ) . ')</span>';
				}

				if ( $relative_file === $filename ) {
					echo '<span class="notice notice-info">' . $file_description . '</span>';
				} else {
					echo $file_description;
				}
				?>
			</a>
		</li>
		<?php
	}
}
```

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

- 4.9.0 — Introduced.

## Связанные

Использует: [`wp_print_theme_file_tree`](https://chugunov.pro/api-wordpress/functions/wp_print_theme_file_tree/), [`get_file_description`](https://chugunov.pro/api-wordpress/functions/get_file_description/), [`self_admin_url`](https://chugunov.pro/api-wordpress/functions/self_admin_url/), [`_e`](https://chugunov.pro/api-wordpress/functions/_e/), [`wp_basename`](https://chugunov.pro/api-wordpress/functions/wp_basename/), [`esc_attr`](https://chugunov.pro/api-wordpress/functions/esc_attr/), [`esc_html`](https://chugunov.pro/api-wordpress/functions/esc_html/), [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`add_query_arg`](https://chugunov.pro/api-wordpress/functions/add_query_arg/).
Используется в: [`wp_print_theme_file_tree`](https://chugunov.pro/api-wordpress/functions/wp_print_theme_file_tree/).

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