register_deactivation_hook() is launched when a plugin is deactivated. For plugin uninstall, there is register_uninstall_hook().
WordPress plugins can also have a file called uninstall.php
that is ran whenever the plugin is uninstalled. To prevent the uninstall.php
file from being triggered directly, the state of a constant called WP_UNINSTALL_PLUGIN
should be checked before launching the codes for uninstall.
Your uninstall.php
could be:
<?php
//if uninstall not called from WordPress exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit ();
global $wpdb;
$sortsearchtitle_db_version = '1.0';
$table = $wpdb->prefix."sortsearchresult";
$wpdb->query("DROP TABLE IF EXISTS $table");
delete_option('sortsearchtitle_db_version');