A couple months ago, I got my first WP plugin in the WP plugin repo. The plugin uses register_activation_hook with an attached function to create some custom MySQL tables to store data.

Now that I'm adding some new features, I need to run some ALTER TABLE table_name ADD new_column queries to add some new columns to the tables (for existing plugin installations).

I'm guessing I should use the upgrader_process_complete hook to run the ALTER TABLE queries?

I'm also guessing I will need to start storing the current plugin version number in the database using update_option('my_plugin_version') and get_option('my_plugin_version') to compare the installed plugin version and the current version available ?

Should I always have the current table structure used, ie:

   $sql= "CREATE TABLE " . $table_name . " (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `field1` text NOT NULL,      
      `field2` text NOT NULL,
      `field3` text NULL,
      PRIMARY KEY  (`id`)
    ) $charset_collate;";

in the register_activation_hook and not just keeping the original table structure, then checking the version to apply the appropriate tables updates for each version number?

1 Answer 1


I guess WordPress' codex article is the way to go https://codex.wordpress.org/Creating_Tables_with_Plugins

and from other articles I've read, upgrader_process_complete is usually used to detect when other plugins are updated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.