register_uninstall_hook()
最后更新于:2021-11-27 21:39:08
register_uninstall_hook( string$file, callable$callback)Sets the uninstallation hook for a plugin.
参数
- $file
-
(string) (Required) Plugin file.
- $callback
-
(callable) (Required) The callback to run when the hook is called. Must be a static method or function.
源文件
文件: gc-includes/plugin.php
function register_uninstall_hook( $file, $callback ) {
if ( is_array( $callback ) && is_object( $callback[0] ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1.0' );
return;
}
/*
* The option should not be autoloaded, because it is not needed in most
* cases. Emphasis should be put on using the 'uninstall.php' way of
* uninstalling the plugin.
*/
$uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
$plugin_basename = plugin_basename( $file );
if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) {
$uninstallable_plugins[ $plugin_basename ] = $callback;
update_option( 'uninstall_plugins', $uninstallable_plugins );
}
}