6

I am converting a bunch of sites to multisite and I am confused about the behavior differences between get_option and get_site_option.

It appears that get_site_option actually means "get_network_wide_option" and get_option means "get_option_for_this_site", and the same for the update versions.

Given this, if a plugin wants to have discrete settings for each site, it needs to use get_option and update_option. On the other hand, if it wants option values to be constant across all sites, then use the get_site_option version.

Is my understanding of this correct?

1 Answer 1

6

Yes, get_site_option() is for data about the whole network.

The irritation comes from a mixed vocabulary: what was a site once is a network nowadays, and what was a blog once is now a site in a network.

wp_get_sites() for example is from version 3.7, it fetches sites in a network, not all networks in an installation. So a site in wp_get_sites() is not the same as a site in get_site_option().

For plugin that should be used in a single-site installation or as network plugins only, you can always use get_site_option(), because on a single site it will fall back to get_option().

One important difference is: normal options are loaded automatically on every requests, so you will hit the cache with get_option(). Site options are not loaded automatically, only some core options. See /wp-includes/option.php wp_load_core_site_options().

To store information for all sites in all networks you have to use a custom table or pick one network in the current installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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