[wp-hackers] A Question On Plugins

Andy Skelton skeltoac at gmail.com
Tue Apr 25 14:47:31 GMT 2006

On 4/25/06, Andy Staines <andy at yellowswordfish.com> wrote:
> I know you guys are in the middle of a big security conference but


> Is this the 'right' way to ensure tables get created or is there a
> better hook to use? And, if so, any ideas why it should fail?

I do it a bit differently. This method had the added benefit of
letting you upgrade the tables just like WP does.

Save your plugin db version as an option. Check the option on every
page load. It's autoloaded so the cost of this operation is trivial.

If the db version in the option is outdated or missing:
$my_queries = "CREATE TABLE foo (...); CREATE TABLE bar (...);"
update your db version option.

Of course, you'll have to clean up that code and make it your own.

When you update the plugin with new table schema, just update
$my_queries and bump the db_version coded in your plugin. It'll see
the outdated version in the options table and run the upgrade.


More information about the wp-hackers mailing list