When the user uninstalls your plugin, you have a clean up job to do. Basically when a user clicks on delete plugin after deactivation it, your plugin should be removed WITH a bit clean up.
You usually would want to remove the plugin specific settings, options or some database entries.
Deactivation hook and uninstall hooks perform different tasks.
The deactivation hook flushes caches/temp files and permalinks while uninstall hook removes options from {$wpdb->prefix}_options and tables from wpdb
Methods to setup the uninstall hook
You can use either of these 2 methods to setup the uninstall hook.
Use register_uninstall_hook() like this:
register_uninstall_hook(__FILE__, 'function');
Creating a uninstall.php file
You create the uninstall.php file in the root folder of your plugin.
The uninstall.php file is run automatically when the plugin is deleted.
To protect against direct access, a good practice is to check for the constant WP_UNINSTALL_PLUGIN in the uninstall.php file before adding other code.
Example from WordPress
This code in uninstall.php file will delete option entries and will drop a database table.
// if uninstall.php is not called by WordPress, die
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
$option_name = 'wporg_option';
delete_option($option_name);
// for site options in Multisite
delete_site_option($option_name);
// drop a custom database table
global $wpdb;
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}mytable");
database deactivation hook options uninstall