switch_theme | WordPress 主题切换停用时触发 钩子
21
2015-01-06
钩子
do_action( 'switch_theme', string $new_name, WP_Theme $new_theme, WP_Theme $old_theme )
描述
wordpress主题切换停用时触发。
参数
$new_name
,( string ) 新主题的名称。
$new_theme
,( WP_Theme ) 新主题的WP_Theme
实例。
$old_theme
,( WP_Theme ) 旧主题的WP_Theme
实例。
返回值
无
划重点
当WordPress主题改变时触发switch_theme
。具体来说,它会在主题切换之后但在下一个请求之前触发。主题开发者应该使用这个钩子在他们的主题被停用时做一些事情。
附加到此挂钩的主题功能仅在停用的主题中触发。要在主题激活时执行某些操作,请使用 after_switch_theme()。
附加到这个动作钩子的函数接收一个参数:一个带有被激活的新主题名称的字符串。
相关函数
来源
文件:wp-includes/theme.php
更新日志
4.5.0
介绍了$old_theme
参数。
1.5.0
介绍。
示例
停用主题时刷新链接重写规则。
add_action( 'switch_theme', 'deactivate_my_theme' ); function deactivate_my_theme( $new_theme ) { flush_rewrite_rules(false); }
停用主题时删除主题的选项。
add_action('switch_theme', 'mytheme_setup_options'); function mytheme_setup_options () { delete_option('mytheme_enable_features'); delete_option('mytheme_enable_catalog'); }
本文由 猫斯基 原创发布。
著作权均归用户本人所有。独家文章转载,请联系本站管理员。获得授权后,须注明本文地址! 本文地址:https://www.maosiji.com/2767.html