register_deactivation_hook

函数
register_deactivation_hook ( $file, $callback )
参数
  • (string) $file The filename of the plugin including the path.
    Required:
  • (callable) $callback The function hooked to the 'deactivate_PLUGIN' action.
    Required:
定义位置
相关方法
register_activation_hookregister_taxonomyunregister_taxonomyregister_metaunregister_meta_key
引入
2.0.0
弃用
-

register_deactivation_hook: 这个函数用来为一个插件注册一个停用钩子。它需要两个参数:$file和$callback。$file是插件文件的路径,$callback是插件停用时将被调用的函数。

设置一个插件的停用钩子。

当一个插件被停用时,动作’deactivate_PLUGINNAME’被调用。在这个钩子的名称中,PLUGINNAME被替换成插件的名称,包括可选的子目录。例如,当插件位于wp-content/plugins/sampleplugin/sample.php,那么这个钩子的名字将变成’deactivate_sampleplugin/sample.php’。

当插件只有一个文件,并且(默认情况下)位于wp-content/plugins/sample.php中时,这个钩子的名称将是’deactivate_sample.php’。

function register_deactivation_hook( $file, $callback ) {
	$file = plugin_basename( $file );
	add_action( 'deactivate_' . $file, $callback );
}

常见问题

FAQs
查看更多 >