# validate_current_theme()

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

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

## Сигнатура

```php
validate_current_theme(): bool
```

## Описание

Самостоятельные темы должны иметь файл шаблона templates/index.html или index.php.
Дочерние темы должны иметь заголовок Template в таблице стилей style.css.
Изначально не проверяет тему по умолчанию, которая является запасной и должна существовать всегда.
Но если её нет, произойдёт откат к последней существующей стандартной теме ядра.
Если активная тема не проходит проверку, тема будет переключена на запасную.
Чтобы отключить это поведение, можно использовать фильтр «validate_current_theme», вернув false.
См. также WP_DEFAULT_THEME

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

`bool`

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

Файл: `wp-includes/theme.php:898`

```php
function validate_current_theme() {
	/**
	 * Filters whether to validate the active theme.
	 *
	 * @since 2.7.0
	 *
	 * @param bool $validate Whether to validate the active theme. Default true.
	 */
	if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) {
		return true;
	}

	if (
		! file_exists( get_template_directory() . '/templates/index.html' )
		&& ! file_exists( get_template_directory() . '/block-templates/index.html' ) // Deprecated path support since 5.9.0.
		&& ! file_exists( get_template_directory() . '/index.php' )
	) {
		// Invalid.
	} elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) {
		// Invalid.
	} elseif ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) {
		// Invalid.
	} else {
		// Valid.
		return true;
	}

	$default = wp_get_theme( WP_DEFAULT_THEME );
	if ( $default->exists() ) {
		switch_theme( WP_DEFAULT_THEME );
		return false;
	}

	/**
	 * If we're in an invalid state but WP_DEFAULT_THEME doesn't exist,
	 * switch to the latest core default theme that's installed.
	 *
	 * If it turns out that this latest core default theme is our current
	 * theme, then there's nothing we can do about that, so we have to bail,
	 * rather than going into an infinite loop. (This is why there are
	 * checks against WP_DEFAULT_THEME above, also.) We also can't do anything
	 * if it turns out there is no default theme installed. (That's `false`.)
	 */
	$default = WP_Theme::get_core_default_theme();
	if ( false === $default || get_stylesheet() === $default->get_stylesheet() ) {
		return true;
	}

	switch_theme( $default->get_stylesheet() );
	return false;
}
```

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

- 6.0.0 — Removed the requirement for block themes to have an index.php template.
- 1.5.0 — Introduced.

## Связанные

Использует: `WP_Theme::get_core_default_theme`, [`wp_installing`](https://chugunov.pro/api-wordpress/functions/wp_installing/), [`switch_theme`](https://chugunov.pro/api-wordpress/functions/switch_theme/), [`get_template_directory`](https://chugunov.pro/api-wordpress/functions/get_template_directory/), [`get_stylesheet_directory`](https://chugunov.pro/api-wordpress/functions/get_stylesheet_directory/), [`is_child_theme`](https://chugunov.pro/api-wordpress/functions/is_child_theme/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/), [`wp_get_theme`](https://chugunov.pro/api-wordpress/functions/wp_get_theme/), `WP_Theme`, [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_Customize_Manager::after_setup_theme`.

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