check_theme_switched()

最后更新于:2021-11-25 20:30:33

check_theme_switched()

Checks if a theme has been changed and runs ‘after_switch_theme’ hook on the next GC load.

源文件

文件: gc-includes/theme.php

function check_theme_switched() {
	$stylesheet = get_option( 'theme_switched' );
	if ( $stylesheet ) {
		$old_theme = gc_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', '_gc_menus_changed' );
			remove_action( 'after_switch_theme', '_gc_sidebars_changed' );
			update_option( 'theme_switched_via_customizer', false );
		}

		if ( $old_theme->exists() ) {
			/**
			 * Fires on the first GC load after a theme switch if the old theme still exists.
			 *
			 * This action fires multiple times and the parameters differs
			 * according to the context, if the old theme exists or not.
			 * If the old theme is missing, the parameter will be the slug
			 * of the old theme.
			 *
			 * @since 3.3.0
			 *
			 * @param string   $old_name  Old theme name.
			 * @param GC_Theme $old_theme GC_Theme instance of the old theme.
			 */
			do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme );
		} else {
			/** This action is documented in gc-includes/theme.php */
			do_action( 'after_switch_theme', $stylesheet, $old_theme );
		}
		flush_rewrite_rules();

		update_option( 'theme_switched', false );
	}
}