What use is the WordPress register_activation_hook() function?

Having been playing around with WordPress Network (Multisite) plugins, mostly internal, not doing much that anyone else would be interested in having. During a plugin’s lifetime it goes through some critical points. The one you can’t avoid is activation. Many also experience deactivation or even deletion. Most will, at some point, be updated. for these critical points the plugin author may want to have certain critical events happen. Setting up options, creating databases, pre-populating meta data. And of course the reverse – deleting said litter.

A quick summary of the register_activation_hook() function:

  • It doesn’t work on multisite. Network activation does not trigger this function
  • Updating the plugin does not trigger it
  • It is triggered every time a plugin is manually re-activated

None of these are my desired behaviour. I usually write my own hook that checks if the plugin version has changed, and fire off my actions.

Which makes me wonder whether the function is out dated, and should be replaced a set of alternative functions. They could perhaps even be actions?

  • register_plugin_activation_hook
  • register_plugin_network_action_hook
  • register_plugin_update_hook
  • register_plugin_update_network_hook

Published by

TCBarrett

Open Source Architect (Web Geek)