Allow get_blog_option(null,...) to hit the cache for the current blog. New return values for add_blog_option, update_blog_option, delete_blog_option. Don't set the cache in those functions if add/update/delete_option failed. see #17883.
git-svn-id: http://svn.automattic.com/wordpress/trunk@18662 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4319712d64
commit
feb2ba5831
|
@ -320,7 +320,7 @@ function update_blog_details( $blog_id, $details = array() ) {
|
||||||
* @since MU
|
* @since MU
|
||||||
* @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
|
* @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
|
||||||
*
|
*
|
||||||
* @param int $blog_id is the id of the blog.
|
* @param int $blog_id Optional. Blog ID, can be null to refer to the current blog.
|
||||||
* @param string $setting Name of option to retrieve. Should already be SQL-escaped.
|
* @param string $setting Name of option to retrieve. Should already be SQL-escaped.
|
||||||
* @param string $default (optional) Default value returned if option not found.
|
* @param string $default (optional) Default value returned if option not found.
|
||||||
* @return mixed Value set for the option.
|
* @return mixed Value set for the option.
|
||||||
|
@ -328,6 +328,9 @@ function update_blog_details( $blog_id, $details = array() ) {
|
||||||
function get_blog_option( $blog_id, $setting, $default = false ) {
|
function get_blog_option( $blog_id, $setting, $default = false ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
if ( null === $blog_id )
|
||||||
|
$blog_id = $wpdb->blogid;
|
||||||
|
|
||||||
$key = $blog_id . '-' . $setting . '-blog_option';
|
$key = $blog_id . '-' . $setting . '-blog_option';
|
||||||
$value = wp_cache_get( $key, 'site-options' );
|
$value = wp_cache_get( $key, 'site-options' );
|
||||||
if ( $value == null ) {
|
if ( $value == null ) {
|
||||||
|
@ -380,14 +383,17 @@ function get_blog_option( $blog_id, $setting, $default = false ) {
|
||||||
* @param int $id The blog id
|
* @param int $id The blog id
|
||||||
* @param string $key The option key
|
* @param string $key The option key
|
||||||
* @param mixed $value The option value
|
* @param mixed $value The option value
|
||||||
|
* @return bool True on success, false on failure.
|
||||||
*/
|
*/
|
||||||
function add_blog_option( $id, $key, $value ) {
|
function add_blog_option( $id, $key, $value ) {
|
||||||
$id = (int) $id;
|
$id = (int) $id;
|
||||||
|
|
||||||
switch_to_blog($id);
|
switch_to_blog($id);
|
||||||
add_option( $key, $value );
|
$return = add_option( $key, $value );
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' );
|
if ( $return )
|
||||||
|
wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' );
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -397,14 +403,17 @@ function add_blog_option( $id, $key, $value ) {
|
||||||
*
|
*
|
||||||
* @param int $id The blog id
|
* @param int $id The blog id
|
||||||
* @param string $key The option key
|
* @param string $key The option key
|
||||||
|
* @return bool True on success, false on failure.
|
||||||
*/
|
*/
|
||||||
function delete_blog_option( $id, $key ) {
|
function delete_blog_option( $id, $key ) {
|
||||||
$id = (int) $id;
|
$id = (int) $id;
|
||||||
|
|
||||||
switch_to_blog($id);
|
switch_to_blog($id);
|
||||||
delete_option( $key );
|
$return = delete_option( $key );
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' );
|
if ( $return )
|
||||||
|
wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' );
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -415,6 +424,7 @@ function delete_blog_option( $id, $key ) {
|
||||||
* @param int $id The blog id
|
* @param int $id The blog id
|
||||||
* @param string $key The option key
|
* @param string $key The option key
|
||||||
* @param mixed $value The option value
|
* @param mixed $value The option value
|
||||||
|
* @return bool True on success, false on failrue.
|
||||||
*/
|
*/
|
||||||
function update_blog_option( $id, $key, $value, $deprecated = null ) {
|
function update_blog_option( $id, $key, $value, $deprecated = null ) {
|
||||||
$id = (int) $id;
|
$id = (int) $id;
|
||||||
|
@ -423,12 +433,14 @@ function update_blog_option( $id, $key, $value, $deprecated = null ) {
|
||||||
_deprecated_argument( __FUNCTION__, '3.1' );
|
_deprecated_argument( __FUNCTION__, '3.1' );
|
||||||
|
|
||||||
switch_to_blog($id);
|
switch_to_blog($id);
|
||||||
update_option( $key, $value );
|
$return = update_option( $key, $value );
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
|
|
||||||
refresh_blog_details( $id );
|
refresh_blog_details( $id );
|
||||||
|
|
||||||
wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');
|
if ( $return )
|
||||||
|
wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue