Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
register_uninstall_hook() - 设置插件的卸载钩子 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / register_uninstall_hook()

register_uninstall_hook( string $file, callable $callback )

设置插件的卸载钩子


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "05a72b61c3c433a210b768fb1819eb7f" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "5eac3a4c3a88fe35eccfdb3bc6176d2d" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "30bc4ce07c870beb0448b1530753ed03" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

hook

registermore...


描述

注册卸载钩子,当用户单击调用插件卸载自身的卸载链接时将调用该挂钩。除非插件钩住动作,否则链接不会激活。

注册卸载挂钩时,插件不应在函数之外运行任意代码。为了使用钩子运行,插件必须包含在内,这意味着在卸载过程中,任何放置在函数外部的代码都将运行。插件不应妨碍卸载过程。

如果没有在插件中运行代码就无法编写插件,那么插件应该创建一个名为“uninstall.php”的文件。在基本插件文件夹中。如果该文件存在,则在卸载过程中将绕过卸载挂钩调用该文件。当插件使用“uninstall.php”时,在执行之前应始终检查‘WP_UNINSTALL_PLUGIN’常量。


参数

$file

(string)(必填) 插件文件。

$callback

(callable)(必填) 调用挂钩时要运行的回调。必须是静态方法或函数。



源码

查看源码 官方文档


更新日志

版本描述
2.7.0开始引入

使用示例

  • 示例1

    在register_activation_hook内执行卸载挂钩

    function your_prefix_activate(){
    	register_uninstall_hook( __FILE__, 'your_prefix_uninstall' );
    }
    register_activation_hook( __FILE__, 'your_prefix_activate' );
    
    // And here goes the uninstallation function:
    function your_prefix_uninstall(){
    	//	codes to perform during unistallation
    }