function add_site_option( $option, $value ) {}

Add a new site option.
Existing options will not be updated. Note that prior to 3.3 this wasn’t the case.


  • string $option: Name of option to add. Expected to not be SQL-escaped.
  • mixed $value: Optional. Option value, can be anything. Expected to not be SQL-escaped.

Return values

returns:False if option was not added and true if option was added.

Defined filters

  • pre_add_site_option_$option
    apply_filters( 'pre_add_site_option_' . $option, $value )

Source code

function add_site_option( $option, $value ) {

	global $wpdb;

	$value = apply_filters( 'pre_add_site_option_' . $option, $value );

	if ( !is_multisite() ) {

		$result = add_option( $option, $value );

	} else {

		$cache_key = "{$wpdb->siteid}:$option";

		if ( false !== get_site_option( $option ) )

			return false;

		$value = sanitize_option( $option, $value );

		wp_cache_set( $cache_key, $value, 'site-options' );

		$_value = $value;

		$value = maybe_serialize( $value );

		$result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) );

		$value = $_value;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: