add_blog_option

Add a new option for a given blog id.

Description

add_blog_option( (int) $id, (string) $option, (mixed) $value ); 

You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is inserted into the database. Remember, resources can not be serialized or added as an option.

You can create options without values and then update the values later. Existing options will not be updated and checks are performed to ensure that you aren't adding a protected WordPress option. Care should be taken to not name options the same as the ones which are protected.

Parameters (3)

0. $id (int)
A blog ID. Can be null to refer to the current blog.
1. $option (string)
Name of option to add. Expected to not be SQL-escaped.
2. $value — Optional. (mixed)
Option value, can be anything. Expected to not be SQL-escaped.

Usage

  1. if ( !function_exists( 'add_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 add. Expected to not be SQL-escaped. 
  8. $option = ''; 
  9.  
  10. // Optional. Option value, can be anything. Expected to not be SQL-escaped. 
  11. $value = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = add_blog_option($id, $option, $value); 
  15.  

Defined (1)

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

/wp-includes/ms-blogs.php  
  1. function add_blog_option( $id, $option, $value ) { 
  2. $id = (int) $id; 
  3.  
  4. if ( empty( $id ) ) 
  5.  
  6. if ( get_current_blog_id() == $id ) 
  7. return add_option( $option, $value ); 
  8.  
  9. switch_to_blog( $id ); 
  10. $return = add_option( $option, $value ); 
  11.  
  12. return $return;