Imagine a WordPress MultiSite Network with plugin Foo in it (but only active on some of the sites). When upgrading plugin Foo from version 1.0 to 2.0, Foo would like to do some work in the database. (For the sake of this exercise, let’s just assume it wants to stop storing data in 10 different wp_options rows, and store it all in a serialized array.)

How can Foo run its foo_db_update script, for each site, when Foo is updated?

A common answer is that Foo should hook into admin_init, and check the current version of Foo against the db-stored version, and see if it needs to run this script. The primary problem here is that it’s not something that can be easily done in a MultiSite environment. This approach might work if I could easily trigger the admin_init events of all sites in the network - with each site’s current plugins loaded - but I don’t know a way to do that.

I’ve tried hooking into wpmu_upgrade_site, and running Upgrade Network after updating Foo to version 2.0. However, that only uses switch_to_blog to act as each site, and doesn’t fully load the plugins for each site it’s switching to. This means that if Foo adds a function to wpmu_upgrade_site, that function won’t fire when Upgrade Network is clicked from the Network Admin.

So, what IS the best way for a plugin to run such a script in a MultiSite environment?

Read more here: How can a plugin run a script after being updated in MultiSite?


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: