get_, update_ and add_site_option()

Summary:  These functions get or set site option variables according to user specification.

Detail:  The full function names with their variables and brief descriptions are as follows:

get_site_option( $key, $default = false, $use_cache = true )

This function checks for the existence of the option named $key.  By default, the function will first in the wp_cache and failing that, in the database.  Should the key exist in the database but not the cache, it will be added.  If it appears in neither location, the $default value “false” will be added to the cache.  By setting $use_default to false, you can override the option to use the cache in the query, but the cache is still updated with the returned value.

add_site_option( $key, $value )

This function first checks for the existence of the option $key in the site meta table, and if that option exists, calls update_site_option().  Otherwise, it first serializes objects and arrays passed as $value, then creates and sets the option. Additionally, this function will destroy any wp-cache’d reference to the option.

update_site_option( $key, $value )

This function is essentially the same as add_site_option in most respects, except that it assumes the option exists and only calls add_site_option if updating the option returns false.  Technically, this would be the more efficient function to call unless it is certain that the option does not exist.

No tag for this post.

No comments yet