register_uninstall_hook [ WordPress Function ]
| Parameters: |
|
| Defined at: |
|
Set the uninstallation hook for a plugin.
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. The plugin, when using the 'uninstall.php' should always check for the 'WP_UNINSTALL_PLUGIN' constant, before executing.
Source
<?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' );
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');
$uninstallable_plugins[plugin_basename($file)] = $callback;
update_option('uninstall_plugins', $uninstallable_plugins);
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/register uninstall hook « WordPress Codex
Description. 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 ...
codex.wordpress.org - WordPress Plugin Deinstall Data Automatically - WP Engineer
Sep 18, 2008 ... A hook for uninstall register_uninstall_hook has to talk to. ... Alternative you can use the hook register_uninstall_hook() , since this one is ...
wpengineer.com - Register_uninstall_hook | WP Code Snippets
Jun 16, 2011 ... This is the seventh article in our plugin development tutorial series. In the last segment, we covered debugging basics, cross-browser testing, ...
wpcodesnippets.info - plugins - How can I delete options with register_uninstall_hook ...
Aug 1, 2011 ... function mr_np_activate(){ // hook uninstall if ( function_exists(' register_uninstall_hook') ) register_uninstall_hook(__FILE__,'mr_np_uninstall'); } ...
wordpress.stackexchange.com
Gebruikersdiscussies [ wordpress.org ]
- lelkoun on "Plugin uninstallation does not work!"
- zamb0n on "Plugin uninstallation does not work!"
- ray on "[Plugin: Configure SMTP] Notice: register_uninstall_hook"
- coffee2code on "[Plugin: Configure SMTP] Notice: register_uninstall_hook"
- ray on "[Plugin: Configure SMTP] Notice: register_uninstall_hook"
- lelkoun on "Plugin uninstallation does not work!"
- lelkoun on "Plugin uninstallation does not work!"
- vegan on "[Plugin: Configure SMTP] Notice: register_uninstall_hook"
- af. on "Optionally remove data on plugin uninstall"