6

I have a multisite instance of WordPress with almost 100 sites. I need to set an option for a network-wide installed plugin but I don't want to go to each site dashboard to set this option by hand. How could I do ?

The option I want to change is a classic option, not a network-wide one. It comes from a plugin that I did not write. Want I need it to change the value of that classic option for all sites in my network at once.

2 Answers 2

5

Excuse me if I'm misunderstanding you, but aren't the functions add_site_option(), update_site_option() and get_site_option() pretty much, they fall back to single site functions, if not used in a multisite environment, only there for the purpose of having network-wide options.


Update:

Regarding your need to change a single site option for all sites in your network. Get all sites of the network with wp_get_sites(), which returns an array of arrays. You can use the array to loop through your single sites in your multisite installation. Make use of switch_to_blog() and restore_current_blog() while looping against the $blog_ids. In between the loop after switching and before restoring, use the single site options functions add_option(), update_option() and get_option() as needed.

2
  • 2
    +1. For more info wordpress.stackexchange.com/questions/181219/…
    – gmazzap
    Commented Jul 20, 2015 at 16:34
  • Sorry for not being clear enough. The option I want to change is a classic option, not a network-wide one. It comes from a plugin that I did not write. Want I need it to change the value of that classic option for all sites in my network at once. Commented Jul 23, 2015 at 8:17
1

You can use WP-CLI to do this now:

wp site list --field=url | xargs -n1 -I % wp --url=% option update my_option my_value

Simply change my_option and my_value according to your needs.

Ref: https://danielbachhuber.com/tip/run-wp-cli-command-wordpress-multisite/

Edit: This doesn't work for complex serialized string values... instead, an easy workaround is temporarily setting your option value to something easy like lolcow and then using the search and replace operator in WP-CLI to input seralized data.

First run:

wp site list --field=url | xargs -n1 -I % wp --url=% option update my_option lolcow

And then:

wp search-replace --network 'lolcow' 'a:1:{s:1:"ex_key";s:2:"account";s:3:"ex_value";s:4:"346345734";}' --all-tables

Ref: https://slickstack.io/forum/topic/how-can-i-update-settings-for-all-sites-in-wp-multisite-network

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.