Changeset 12615 for trunk/wp-includes/functions.php
- Timestamp:
- 01/06/2010 11:57:35 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r12584 r12615 3258 3258 3259 3259 function get_site_option( $key, $default = false, $use_cache = true ) { 3260 global $wpdb; 3261 3260 3262 // Allow plugins to short-circuit site options. 3261 3263 $pre = apply_filters( 'pre_site_option_' . $key, false ); … … 3263 3265 return $pre; 3264 3266 3265 $value = get_option($key, $default); 3267 if ( !is_multisite() ) { 3268 $value = get_option($key, $default); 3269 } else { 3270 $cache_key = "{$wpdb->siteid}:$key"; 3271 3272 if ( $use_cache == true && $value = wp_cache_get($cache_key, 'site-options') ) 3273 return $value; 3274 3275 $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ); 3276 3277 if ( is_null($value) ) 3278 $value = $default; 3279 3280 $value = maybe_unserialize( $value ); 3281 3282 wp_cache_set( $cache_key, $value, 'site-options' ); 3283 } 3266 3284 3267 3285 return apply_filters( 'site_option_' . $key, $value ); … … 3270 3288 // expects $key, $value not to be SQL escaped 3271 3289 function add_site_option( $key, $value ) { 3290 global $wpdb; 3291 3272 3292 $value = apply_filters( 'pre_add_site_option_' . $key, $value ); 3273 $result = add_option($key, $value); 3293 3294 if ( !is_multisite() ) { 3295 $result = add_option($key, $value); 3296 } else { 3297 $cache_key = "{$wpdb->siteid}:$key"; 3298 3299 if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid ) ) ) 3300 return update_site_option( $key, $value ); 3301 3302 $value = sanitize_option( $key, $value ); 3303 wp_cache_set( $cache_key, $value, 'site-options'); 3304 3305 $value = maybe_serialize($value); 3306 3307 $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $key, 'meta_value' => $value) ); 3308 } 3309 3274 3310 do_action( "add_site_option_{$key}", $key, $value ); 3311 do_action( "add_site_option", $key, $value ); 3312 3275 3313 return $result; 3276 3314 } 3277 3315 3278 3316 function delete_site_option( $key ) { 3279 $result = delete_option($key); 3317 global $wpdb; 3318 3319 //wpmu_protect_special_option( $key ); @todo 3320 3321 do_action( 'pre_delete_site_option_' . $key ); 3322 3323 if ( !is_multisite() ) { 3324 $result = delete_option($key); 3325 } else { 3326 $option = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid ) ); 3327 if ( is_null( $option ) || !$option->meta_id ) 3328 return false; 3329 $cache_key = "{$wpdb->siteid}:$key"; 3330 wp_cache_delete( $cache_key, 'site-options' ); 3331 3332 $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid ) ); 3333 } 3334 3280 3335 do_action( "delete_site_option_{$key}", $key ); 3336 do_action( "delete_site_option", $key ); 3281 3337 return $result; 3282 3338 } … … 3284 3340 // expects $key, $value not to be SQL escaped 3285 3341 function update_site_option( $key, $value ) { 3342 global $wpdb; 3343 3286 3344 $oldvalue = get_site_option( $key ); 3287 3345 $value = apply_filters( 'pre_update_site_option_' . $key, $value, $oldvalue ); 3288 $result = update_option($key, $value); 3346 3347 if ( $value == $oldvalue ) 3348 return false; 3349 3350 if ( !is_multisite() ) { 3351 $result = update_option($key, $value); 3352 } else { 3353 $cache_key = "{$wpdb->siteid}:$key"; 3354 3355 if ( $value && !$wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ) ) 3356 return add_site_option( $key, $value ); 3357 $value = sanitize_option( $key, $value ); 3358 wp_cache_set( $cache_key, $value, 'site-options' ); 3359 3360 $value = maybe_serialize($value); 3361 $result = $wpdb->update( $wpdb->sitemeta, array('meta_value' => $value), array('site_id' => $wpdb->siteid, 'meta_key' => $key) ); 3362 } 3363 3289 3364 do_action( "update_site_option_{$key}", $key, $value ); 3365 do_action( "update_site_option", $key, $value ); 3290 3366 return $result; 3291 3367 }
Note: See TracChangeset
for help on using the changeset viewer.