get_blog_option

Retrieve option value for a given blog id based on name of option.

Description

get_blog_option( (int) $id, (string) $option, (bool) $default = false ); 

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 (3)

0. $id (int)
A blog ID. Can be null to refer to the current blog.
1. $option (string)
Name of option to retrieve. Expected to not be SQL-escaped.
2. $default — Optional. (bool) => false
Default value to return if the option does not exist.

Usage

  1. if ( !function_exists( 'get_blog_option' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-blogs.php'; 
  3.  
  4. // A blog ID. Can be null to refer to the current blog. 
  5. $id = -1; 
  6.  
  7. // Name of option to retrieve. Expected to not be SQL-escaped. 
  8. $option = ''; 
  9.  
  10. // Optional. Default value to return if the option does not exist. 
  11. $default = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_blog_option($id, $option, $default); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-blogs.php  
  1. function get_blog_option( $id, $option, $default = false ) { 
  2. $id = (int) $id; 
  3.  
  4. if ( empty( $id ) ) 
  5.  
  6. if ( get_current_blog_id() == $id ) 
  7. return get_option( $option, $default ); 
  8.  
  9. switch_to_blog( $id ); 
  10. $value = get_option( $option, $default ); 
  11.  
  12. /** 
  13. * Filters a blog option value. 
  14. * The dynamic portion of the hook name, `$option`, refers to the blog option name. 
  15. * @since 3.5.0 
  16. * @param string $value The option value. 
  17. * @param int $id Blog ID. 
  18. */ 
  19. return apply_filters( "blog_option_{$option}", $value, $id );