Just as there is an activation function, there is also a deactivation function. This is called the register_deactivation_hook() function. This function is triggered when your plugin is deactivated in the WordPress Plugins screen. This function accepts the same two parameters as the previous activation function.
<?php register_deactivation_hook( $file, $function ); ?>
Parameters:
1. $file – (string) (required) Path to the primary plugin file
2.$function – (string) (required) The function to be executed when the plugin is activated
Example
<?php /* Plugin Name: myPlugin Plugin URI: your url address Description: my first wordpress plugin WordPress admin interface Version: 1.0 Author: you name Author URI: License: GPLv2 */ register_deactivation_hook(__FILE__,'firstRunOnDeActivation'); function firstRunOnDeActivation() { // any statements to delete files etc.. } ?>