函数原型
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.
函数返回值
无
函数位置
File: wp-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 );
}
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |

