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
Related Posts:
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- How To Activate Plugins via Code?
- Activate a plugin through PHPMyAdmin or FTP?
- How to check if a theme is active?
- Pluggable function and activation check?
- Automatically install wordpress plugin at theme activation
- Show a confirm message before plug-in activation
- Function to activate WordPress theme inside a plugin
- Activate Plugin which is in subfolder?
- explanation for activate_plugin function in wordpress core
- Remote plugin activation hook
- Force plugin to fail activation
- WordPress register_activation_hook table creation not working
- Multisite: Activate plugin for subsites only?
- The plugin generated x characters of unexpected output, $wpdb not defined
- Correct way to use register_activation_hook
- Cannot run the code after I activate the plugin
- wordpress in nginx docker container connected to php:8-fpm container and mariadb container isn’t creating any tables on plugin activation
- Unable to activate wordpress importer after installing it
- How to include plugin without activation?
- Auto add content such as pages upon plugin activation?
- Detect when any plugin is activated or deactivated
- How to automate wordpress plugin activate and deactivate by php logic?
- Default Plugin Settings Not Writing to Database
- Plugin won’t activate – cannot declare class (already in use)
- Plugin Deactivate Self on Activation Errors
- How to activate plugins for my WordPress sites from a remote server
- register_activation_hook with include file [closed]
- Prevent a plugin from being automatically activated
- Is any information available in PHP files in WP about plugin activation history?
- Activated plugin is stored as an object, rather than as a path
- Own plugin corrups plugin-activation
- How to check if tables in WordPress still exists after activations
- How to block plugin activations with no known user or coming from unknown IP address range?
- Run plugins only on certain pages
- Are functions in main plugin file called before function bound to register_activation_hook runs?
- Force file download on plugin activation
- WordPress user account activation
- Multiple instance of data in plugin custom database table on plugin activation
- Why this function not working for install database on plugin activation
- register_activation_hook in oop approach
- How to create multiple database tables on plugin activation?
- Run function on plugin activation before plugin is loaded
- rewrite_rules() not applying rules on plugin activation only after permalinks menu is clicked
- register_activation_hook() not working as expected
- Sub Plugin deactivation when Parent Plugin deactivate
- Advanced WordPress plugin activation detection
- Apparent errer when installing plugin
- Activate a plugin via a SQL query
- My plugin does not install correctly if a previous version is still installed
- Is there existing plugins to “Click-to-Launch” embedded Flash / SWF content?
- Activation flow of a plugin in a multisite environment
- How to run flush_rewrite_rules on activation after i register my custom post type using WordPress Boilerplate Plugin
- How to check for already existing plugin versions on activation? and prevent errors
- how to enable/activate a plugin per Cpanel
- My WordPress activation hook isn’t working
- Cannot modify header information – headers already sent during plugin activation
- Error Copying Directory On Plugin Activation
- WordPress hook source
- API calls on plugin activation or init?
- Different plugins activated online and offline
- Problems with installing and deleting plugins
- Plugin De/Activation Not Firing On MultiSite install
- Custom Table doesn’t create on plugin activation
- Activate plugins by a theme’s functions.php?
- Is it possible to send user new password after they clicking on forgot password in word press
- why i cannot see some plugins while they are enabled on network admin page?
- Install theme as part of a plugin
- “Add Media” button in custom plugin
- Disabled plugins are they security holes – rumor or reality?
- When coding a WordPress theme, where does the theme (i.e. the presentation) end and the plugin (i.e. the functionality) begin?
- Core framework/helpers for logging stuff?
- Disable Specific Widgets on Selected Pages of a WordPress Website?
- How to handel multiple checkbox field in the admin settings page with Settings API
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- Files being generated in multiple directories supposedly by WordPress (advanced_settings.php and common_config.php)
- Is there a plugin that allows a user of your site to get an email from you with an attachment?
- Is there a plugin that makes extnernal links open in new window, BUT [closed]
- plugings request url is the old url
- Saving Custom Post types and fields to a custom table
- WooCommerce shop page orderby [closed]
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- How to delete page by deactivating plugin
- Stop Plugin Enumeration [closed]
- Sticky option for custom post types without using custom fields or plugins
- Let users sell video in my website [closed]
- WordPress Social Sharing Icons – Custom Placement
- check uncategorized category by default
- Using meta_query in a WP_Query not working for numbers properly
- How to get rid of Ellipsis on Woocommerce [Essential] Theme [closed]
- How to copy the all WordPress media items to another custom plugin folder?
- Bulk Edit Media Library alt, caption, image names
- Child theme modifications not showing up
- Moving a few select DB tables to a new WP instance
- How to get the total count of Favorite/Favorited authors
- How to create a new database table whenever user changes options
- How do I locate specific file in a post that affects ssl?
- Looking for Plugin that displays Facebook group’s photos [closed]
- Publishing tweets from wordpress [closed]
- How do I put a word-press blog into my static site without installing wordpress on server?