Write a script to change plugin settings across an entire network

I've been wondering about this for a little while now. There are times when I need to make the same change to a plugin across an entire network - previously I've been going through each site an changing the settings individually, but this is getting a bit long winded as my network grows.

An example is as follows. I use Visual composer on my network, often, when I update the plugin, new elements are added to VC. With new elements, you have to manually activate them on each individual site. I'd rather learn how to write a script that will change these settings across my entire network.

Is something like this possible to do?

    • Samuel
      • The Incredible Code Injector

      Hi @Jude, thanks for your reply, and apologies for my delayed response.

      Let's say for example then, that across all my sites, I wanted to run a script that changes "option_value" in a row called "clientside_options" in my "wp_options" table from:

      [code a] to [code b] (I would paste the contents of that row, but it's huge!).

      But obviously, to churn it out across al sites in my network, so it would be in the table wp_#_options. How would I do this?

  • Jude
    • DEV MAN

    Hey Samuel

    Basically ... you'll need to do the following:

    1) Get a list of all the blog IDs in the network/sub-network. If using a vanilla installation, this can be found in the wp_blogs table. Just do a simple SELECT query to load up an array, then you can loop through to add each blog to your main query.

    2) Create a loop that adds each blog to a large query. You'll need to be JOINing tables together and searching based on blog_id (from wp_blogs), clientside_options (from wp_options), and the option_value. This would be an UPDATE query.

    Like I said, it's not a simple SQL statement. Please take backups before trying .. it may need a bit of trial and error before getting right.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.