Codex tools: Log in / create account
The function register_activation_hook (introduced in WordPress 2.0) registers a plugin function to be run when the plugin is activated.
This is easier than using the activate_pluginname action.
<?php register_activation_hook($file, $function); ?>
If you have a function called myplugin_activate() in the main plugin file at either
use this code:
register_activation_hook( __FILE__, 'myplugin_activate' );
This will call the myplugin_activate() function on activation of the plugin. This is a more reliable method than using the activate_pluginname action.
See also register_deactivation_hook