PressTigers

Using Uninstall Hook to Delete Plugin

When you install a plugin, you may create different database entries or define rewrite rules. On deleting a plugin, it may require a cleanup as you do upon plugin activation. The items that should be clear out can be rewrite rules added by the plugin, options/settings specific to the plugin, or other database values. It is not encouraged to write a code on deactivation hook as user may want to reactivate the plugin with older data.

Instead of writing a code in deactivation hook, uninstall.php file containing the hook should be used. This hook checks the WP_UNINSTALL_PLUGIN constant before proceeding the plugin deletion.

The WP_UNINSTALL_PLUGIN constant is defined by WordPress only if an uninstall.php file is present in the plugin folder. It cannot be accessed directly except at the time of plugin being deleted.

Here is an example of uninstall.php file that performs different operations on executing plugin delete request:

User Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Get in Touch