Retrieves option value for a given blog id based on name of option.
Description
If the option does not exist or does not have a value, then the return value will be false. This is useful to check whether you need to install an option and is commonly used during installation of plugin options and to test whether upgrading is required.
If the option was serialized then it will be unserialized when it is returned.
Parameters
$id
intrequired- A blog ID. Can be null to refer to the current blog.
$option
stringrequired- Name of option to retrieve. Expected to not be SQL-escaped.
$default_value
mixedoptional- Default value to return if the option does not exist.
Default:
false
Source
function get_blog_option( $id, $option, $default_value = false ) {
$id = (int) $id;
if ( empty( $id ) ) {
$id = get_current_blog_id();
}
if ( get_current_blog_id() === $id ) {
return get_option( $option, $default_value );
}
switch_to_blog( $id );
$value = get_option( $option, $default_value );
restore_current_blog();
/**
* Filters a blog option value.
*
* The dynamic portion of the hook name, `$option`, refers to the blog option name.
*
* @since 3.5.0
*
* @param string $value The option value.
* @param int $id Blog ID.
*/
return apply_filters( "blog_option_{$option}", $value, $id );
}
Hooks
- apply_filters( “blog_option_{$option}”,
string $value ,int $id ) Filters a blog option value.
Changelog
Version | Description |
---|---|
MU (3.0.0) | Introduced. |
This function is only available if WordPress has been installed and configured as a multisite install. Check function_exists() or use is_multisite() before calling get_blog_option() .