Codex

Function Reference/register deactivation hook

The function register_deactivation_hook (introduced in WordPress 2.0) registers a plugin function to be run when the plugin is deactivated.

Usage and parameters

 <?php register_deactivation_hook($file$function); ?> 

$file
(string) Path to the main plugin file inside the wp-content/plugins directory. A full path will work.
$function
(callback) The function to be run when the plugin is deactivated. Any of PHP's callback pseudo-types will work.

Examples

If you have a function called myplugin_deactivate() in the main plugin file at either

  • wp-content/plugins/myplugin.php or
  • wp-content/plugins/myplugin/myplugin.php

use this code:

register_deactivation_hook( __FILE__, 'myplugin_deactivate' );

This will call the myplugin_deactivate() function on deactivation of the plugin.