1

In the codex it is explained how to hook to plugin_loaded and check the version of the currently installed plugin against what's registered in the options, then realise if you need to upgrade the plugin table.

Question is - what's the method to do it with a multisite plugin that has custom database tables for each network blog? If I hook into plugin_loaded then a random user who happens to be the first that executes the code will need to take all the load of this potentially huge and long process.

Isn't there any manual way to do it? somehow via cron? other suggestions?

1

You could just add a check for is_admin() and current_user_can("update_plugins") to make sure you're running only for admin users that are currently in wp-admin. Any user browsing the front end won't notice anything, logged in or not.

You will probably also want to make sure that this runs only once to avoid race conditions that would produce database errors e.g. running the same ALTER TABLE add ... twice.

2
  • That's a good idea. However, how to prevent incompatibility between the code base and the database version in the short window of time before the plugin db schema is fully updated? (i..e for a given random end user, not an admin) – shaharsol Oct 8 '17 at 10:51
  • That's harder to do with the way WP updates plugins. You could disable new features that would break with old table-schema versions based on the current schema version. You'll have to decide whether the added effort during development is worth it to not throw (noticable) errors for some visitors during updates. – janh Oct 8 '17 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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