register_deactivation_hook

Set the deactivation hook for a plugin.

Description

register_deactivation_hook( (string) $file, (callable) $function ); 

When a plugin is deactivated, the action deactivate_PLUGINNAME hook is called. In the name of this hook, PLUGINNAME is replaced with the name of the plugin, including the optional subdirectory. For example, when the plugin is located in wp-content/plugins/sampleplugin/sample.php, then the name of this hook will become deactivate_sampleplugin/sample.php..

When the plugin consists of only one file and is (as by default) located at wp-content/plugins/sample.php the name of this hook will be 'deactivate_sample.php'.

Parameters (2)

0. $file (string)
The filename of the plugin including the path.
1. $function (callable)
The function hooked to the deactivate_PLUGIN action.

Usage

  1. if ( !function_exists( 'register_deactivation_hook' ) ) { 
  2. require_once ABSPATH . WPINC . '/plugin.php'; 
  3.  
  4. // The filename of the plugin including the path. 
  5. $file = ''; 
  6.  
  7. // The function hooked to the 'deactivate_PLUGIN' action. 
  8. $function = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = register_deactivation_hook($file, $function); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/plugin.php  
  1. function register_deactivation_hook($file, $function) { 
  2. $file = plugin_basename($file);