设置插件的停用挂钩。
原型
register_deactivation_hook( string $file, callable $function )
描述
当停用插件时,将调用操作’deactivate_PLUGINNAME’挂钩。在此挂钩的名称中,PLUGINNAME将替换为插件的名称,包括可选的子目录。例如,当插件位于wp-content / plugins / sampleplugin / sample.php中时,此挂钩的名称将变为“deactivate_sampleplugin / sample.php”。
参数
$file
(string)
(Required)
插件的文件名包括路径。
$function
(callable)
(Required)
该函数挂钩到’deactivate_PLUGIN’操作。
源文件
路径:wp-includes/plugin.php
<?php
...
function register_deactivation_hook($file, $function) {
$file = plugin_basename($file);
add_action('deactivate_' . $file, $function);
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/register_deactivation_hook/