WP Activation And Deactivation

I’ve made a specimen document for the module to demo in the event that you’d like to skirt the hard coding. Basically download this record (rename it to .php) or duplicate/glue the code into another PHP archive and transfer this to your/wp-content/modules registry.

Modules will be on inert status naturally. We can tap on the enact join under the module name to actuate the module. Once the module is effectively enacted, its components will get affected to your site.

Additionally you ought to have the capacity to see deactivate join rather than enact join after a fruitful actuation. Tapping the deactivate connection will return the status of the module to its unique inert status.

Once completed you’ll want to access the WordPress administration panel and browse your current set of plugins.

WordPress provides a concept called hooks, where you can trigger certain tasks to add new behavior or modify existing behavior. So let’s look into the code for activation and deactivation hooks.

function example_activation() {


register_activation_hook(__FILE__, ‘example_activation’);


function example_deactivation() {


register_deactivation_hook(__FILE__, ‘example_deactivation’);

Following things we can do inside plugin activation/deactivation:-

  • Create custom database tables on activation to store data and remove tables on deactivation.
  • Any other necessary task you need to execute in activation.
  • Create custom options for plugins and activation and reset in deactivation.
  • Validate other dependent plugin on activation.

Leave a Reply