^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数check_theme_switched()用法示例

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

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈