Codex tools: Log in
Sets the uninstallation hook for a plugin. Available since WordPress 2.7.
Registers the uninstall hook that will be called when the user clicks on the uninstall link that calls for the plugin to uninstall itself. The link won't be active unless the plugin hooks into the action.
The plugin should not run arbitrary code outside of functions, when registering the uninstall hook. In order to run using the hook, the plugin will have to be included, which means that any code laying outside of a function will be run during the uninstall process. The plugin should not hinder the uninstall process.
If the plugin can not be written without running code within the plugin, then the plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook.
When using 'uninstall.php' the plugin should always check for the
WP_UNINSTALL_PLUGIN constant, before executing. The
WP_UNINSTALL_PLUGIN constant is defined by WordPress at runtime during a plugin uninstall, it will not be present if 'uninstall.php' is requested directly.
<?php register_uninstall_hook($file, $callback) ?>
//if uninstall not called from WordPress exit if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) exit (); delete_option('example');
Emphasis is put on using the 'uninstall.php' way of uninstalling the plugin rather than register_uninstall_hook.