返回介绍

check_theme_switched()

发布于 2017-09-10 21:40:44 字数 2317 浏览 1115 评论 0 收藏 0

check_theme_switched()

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


description

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 );
	}
}

更新日志

Versiondescription
3.3.0Introduced.

相关函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文