A question about register_activation hook

The register_activation_hook() is actually just a wrapper for add_action('activate_' . $file, $function); and is only executed when a plugin is activated.

This action/function is meant to be used by anything that should only execute once when the plugin is activated, things which would include stuff like

  • adding custom terms to taxonomies

  • create new database tables or rows

  • running one time db processes which might include updating certain tables, columns or rows

  • flush rewrite rules

On the opposite, register_deactivation_hook() only executes when a plugin is deactivated. This hook/function/action is meant for running processes to clean up after the plugin, which may include

  • restoring db tables, row or columns which was altered

  • removing custom db tables which was added by the plugin

  • removing any custom options which was added by the plugin that would not be necessary anymore