I’m trying to understand the difference between get_site_option() and get_blog_option().
Are blog and site two different things? Apologies if this question seems basic, but when referring to a WordPress website, I’ve always used both terms very loosely (to mean the same thing). I’m now wondering if there is a difference?
get_option()
returns an option for the current blog.
In single site installation, the current blog is the only blog. So get get_option()
returns the option for it.
get_site_option()
is used to retrieve an option network-wide. It means that you can get the same option from any site of the network.
When this function is used in single installation, it normally returns the same thing of get_option()
. The value may change because get_site_option()
trigger filter hooks that are not triggered by get_option()
.
Note that once the $wpdb->options
table is blog-specific, network-wide options are stored in the $wpdb->sitemeta
table, that is specific of multisite installations.
get_blog_option()
is the only among the three functions that doesn’t receive the option name as 1st argument, but its 1st argument is $blog_id
.
In fact, it is used in multisite installations to retrieve an option from a specific blog whose the id is known.
What this function does is:
switch_to_blog( $blog_id );
$value = get_option( $option, $default );
restore_current_blog();
return $value;
If $blog_id
is the same of current blog id, WordPress just skips the switch_to_blog
part and just calls get_option()
.
This function is defined in the file wp-includes/ms-blogs.php
that is loaded only for multisite installation, so get_blog_option()
is not defined in single site installations.