check_theme_switched() - WordPress 函数参考中文文档

返回介绍

check_theme_switched()

发布于 2017-09-10 字数2314 浏览 1024 评论 0

check_theme_switched()

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


描述

See ‘after_switch_theme’.


源代码

File: wp-includes/theme.php

function check_theme_switched() {
	if ( $stylesheet = get_option( 'theme_switched' ) ) {
		$old_theme = wp_get_theme( $stylesheet );

		// Prevent retrieve_widgets() from running since Customizer already called it up front
		if ( get_option( 'theme_switched_via_customizer' ) ) {
			remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
			update_option( 'theme_switched_via_customizer', false );
		}

		if ( $old_theme->exists() ) {
			/**
			 * Fires on the first WP 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 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 );
		}
		flush_rewrite_rules();

		update_option( 'theme_switched', false );
	}
}

更新日志

Version 描述
3.3.0 Introduced.

相关函数

Uses

  • wp-includes/theme.php:
    after_switch_theme
  • wp-includes/theme.php:
    wp_get_theme()
  • wp-includes/plugin.php:
    remove_action()
  • wp-includes/plugin.php:
    do_action()
  • wp-includes/option.php:
    update_option()
  • wp-includes/option.php:
    get_option()
  • wp-includes/rewrite.php:
    flush_rewrite_rules()
  • Show 2 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!