Is it possible to wrap code in a special function that only executes the first time the plugin is activated?
I have some database code I need to run on plugin activation, but the code need not run again after that.
Is it possible to wrap code in a special function that only executes the first time the plugin is activated?
I have some database code I need to run on plugin activation, but the code need not run again after that.
You must be logged in to post a comment.
Yes, this is possible. You can register a plugin activation hook that only gets run when the plugin gets activated. I dredged up an old plugin I wrote for some example code:
http://codex.wordpress.org/Function_Reference/register_activation_hook
remember also once your plugin is being deactivated by yourself/user you can remove any tables options that you have stored in the wp database, I wrote a little post about this recently talking about the wp register_deactivation_hook() function..
http://www.martin-gardner.co.uk/how-to-get-your-wordpress-plugin-to-drop-table-from-the-database/