Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 主题删除后的Wordpress挂钩_Php_Wordpress_Plugins_Themes - Fatal编程技术网

Php 主题删除后的Wordpress挂钩

Php 主题删除后的Wordpress挂钩,php,wordpress,plugins,themes,Php,Wordpress,Plugins,Themes,我在wordpress中创建了主题,现在我在外观中创建了一些主题选项页面。 现在,若用户从系统中删除主题,我想从数据库中删除任何数据 function register_my_setting() { register_setting( 'settings_grup', 'array_post_redirect'); } add_action( 'admin_init', 'register_my_setting' ); 现在我想删除选项,但我找到的唯一解决方案是hook:switch

我在wordpress中创建了主题,现在我在外观中创建了一些主题选项页面。 现在,若用户从系统中删除主题,我想从数据库中删除任何数据

function register_my_setting() {
    register_setting( 'settings_grup', 'array_post_redirect');
} 
add_action( 'admin_init', 'register_my_setting' );
现在我想删除选项,但我找到的唯一解决方案是hook:switch_主题和unregister_设置函数。有没有更好的钩子来完成这个任务

function un_register_my_setting() {
    unregister_setting ( 'settings_grup', 'array_post_redirect');
} 
add_action( 'switch_theme', 'un_register_my_setting' );

有一个非常好的教程向你展示了如何为你的主题创建一个
register\u deactivation\u hook
。默认情况下,Wordpress对于主题(如插件)没有此功能,但只要稍加调整,您就可以复制主题的行为

作为参考,它过去是这样做的(我相信3.1之前):


如果我使用after_switch_主题和unregister_设置,可以。主题仍在使用中,可以激活。但数据不是(数据库中没有跟踪),所以必须重新配置吗?正确吗?如果我正确理解您的问题(并且您正确删除了所有数据),那么是的,它应该需要重新配置。
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) { 
     // do your stuff 
}