# check_theme_switched()

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

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

## Сигнатура

```php
check_theme_switched()
```

## Описание

См. 'after_switch_theme'.

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

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

```php
function check_theme_switched() {
	$stylesheet = get_option( 'theme_switched' );

	if ( $stylesheet ) {
		$old_theme = wp_get_theme( $stylesheet );

		// Prevent widget & menu mapping from running since Customizer already called it up front.
		if ( get_option( 'theme_switched_via_customizer' ) ) {
			remove_action( 'after_switch_theme', '_wp_menus_changed' );
			remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
			update_option( 'theme_switched_via_customizer', false );
		}

		if ( $old_theme->exists() ) {
			/**
			 * Fires on the next WP load after the theme has been switched.
			 *
			 * The parameters differ according to whether the old theme exists or not.
			 * If the old theme is missing, the old name will instead be the slug
			 * of the old theme.
			 *
			 * See 'switch_theme'.
			 *
			 * @since 3.3.0
			 *
			 * @param string   $old_name  Old theme name.
			 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
			 */
			do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme );
		} else {
			/** This action is documented in wp-includes/theme.php */
			do_action( 'after_switch_theme', $stylesheet, $old_theme );
		}

		flush_rewrite_rules();

		update_option( 'theme_switched', false );
	}
}
```

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

- 3.3.0 — Introduced.

## Связанные

Использует: [`remove_action`](https://chugunov.pro/api-wordpress/functions/remove_action/), [`flush_rewrite_rules`](https://chugunov.pro/api-wordpress/functions/flush_rewrite_rules/), [`wp_get_theme`](https://chugunov.pro/api-wordpress/functions/wp_get_theme/), `WP_Theme`, [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/), [`update_option`](https://chugunov.pro/api-wordpress/functions/update_option/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/).

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