Ticket #21270: 21270.3.diff
File 21270.3.diff, 7.1 KB (added by , 13 years ago) |
---|
-
wp-includes/ms-blogs.php
307 307 } 308 308 309 309 /** 310 * Retrieve option value based on setting name and blog_id.310 * Retrieve option value for a given blog id based on name of option. 311 311 * 312 312 * If the option does not exist or does not have a value, then the return value 313 313 * will be false. This is useful to check whether you need to install an option 314 314 * and is commonly used during installation of plugin options and to test 315 315 * whether upgrading is required. 316 316 * 317 * There is a filter called 'blog_option_$option' with the $option being 318 * replaced with the option name. The filter takes two parameters. $value and 319 * $blog_id. It returns $value. 320 * The 'option_$option' filter in get_option() is not called. 317 * If the option was serialized then it will be unserialized when it is returned. 321 318 * 322 319 * @since MU 323 * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.324 320 * 325 * @param int $ blog_id Optional. Blog ID, can be null to refer to the current blog.326 * @param string $ setting Name of option to retrieve. Should alreadybe SQL-escaped.327 * @param string $default (optional) Default value returned if option not found.321 * @param int $id A blog ID. Can be null to refer to the current blog. 322 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. 323 * @param mixed $default Optional. Default value to return if the option does not exist. 328 324 * @return mixed Value set for the option. 329 325 */ 330 function get_blog_option( $ blog_id, $setting, $default = false ) {331 global $wpdb;326 function get_blog_option( $id, $option, $default = false ) { 327 $id = (int) $id; 332 328 333 if ( null === $blog_id)334 $blog_id = $wpdb->blogid;329 if ( $id == get_current_blog_id() ) 330 return get_option( $option, $default ); 335 331 336 $key = $blog_id . '-' . $setting . '-blog_option'; 337 $value = wp_cache_get( $key, 'site-options' ); 338 if ( $value == null ) { 339 if ( $blog_id == $wpdb->blogid ) { 340 $value = get_option( $setting, $default ); 341 $notoptions = wp_cache_get( 'notoptions', 'options' ); 342 if ( isset( $notoptions[$setting] ) ) { 343 wp_cache_set( $key, 'noop', 'site-options' ); 344 $value = $default; 345 } elseif ( $value == false ) { 346 wp_cache_set( $key, 'falsevalue', 'site-options' ); 347 } else { 348 wp_cache_set( $key, $value, 'site-options' ); 349 } 350 return apply_filters( 'blog_option_' . $setting, $value, $blog_id ); 351 } else { 352 $blog_prefix = $wpdb->get_blog_prefix( $blog_id ); 353 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting ) ); 354 if ( is_object( $row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 355 $value = $row->option_value; 356 if ( $value == false ) 357 wp_cache_set( $key, 'falsevalue', 'site-options' ); 358 else 359 wp_cache_set( $key, $value, 'site-options' ); 360 } else { // option does not exist, so we must cache its non-existence 361 wp_cache_set( $key, 'noop', 'site-options' ); 362 $value = $default; 363 } 364 } 365 } elseif ( $value == 'noop' ) { 366 $value = $default; 367 } elseif ( $value == 'falsevalue' ) { 368 $value = false; 369 } 370 // If home is not set use siteurl. 371 if ( 'home' == $setting && '' == $value ) 372 return get_blog_option( $blog_id, 'siteurl' ); 332 switch_to_blog( $id ); 333 $option = get_option( $option, $default ); 334 restore_current_blog(); 373 335 374 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting ) 375 $value = untrailingslashit( $value ); 376 377 return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id ); 336 return $option; 378 337 } 379 338 380 339 /** 381 * Add a n option for a particular blog.340 * Add a new option for a given blog id. 382 341 * 342 * You do not need to serialize values. If the value needs to be serialized, then 343 * it will be serialized before it is inserted into the database. Remember, 344 * resources can not be serialized or added as an option. 345 * 346 * You can create options without values and then update the values later. 347 * Existing options will not be updated and checks are performed to ensure that you 348 * aren't adding a protected WordPress option. Care should be taken to not name 349 * options the same as the ones which are protected. 350 * 383 351 * @since MU 384 352 * 385 * @param int $id The blog id386 * @param string $ key The option key387 * @param mixed $value The option value388 * @return bool True on success, false on failure.353 * @param int $id A blog ID. Can be null to refer to the current blog. 354 * @param string $option Name of option to add. Expected to not be SQL-escaped. 355 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. 356 * @return bool False if option was not added and true if option was added. 389 357 */ 390 function add_blog_option( $id, $ key, $value ) {358 function add_blog_option( $id, $option, $value ) { 391 359 $id = (int) $id; 392 360 393 switch_to_blog($id); 361 if ( $id == get_current_blog_id() ) 362 return add_option( $option, $value ); 363 364 switch_to_blog( $id ); 394 365 $return = add_option( $key, $value ); 395 366 restore_current_blog(); 396 if ( $return ) 397 wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' ); 367 398 368 return $return; 399 369 } 400 370 401 371 /** 402 * Delete an option for a particular blog.372 * Removes option by name for a given blog id. Prevents removal of protected WordPress options. 403 373 * 404 374 * @since MU 405 375 * 406 * @param int $id The blog id407 * @param string $ key The option key408 * @return bool True on success, false on failure.376 * @param int $id A blog ID. Can be null to refer to the current blog. 377 * @param string $option Name of option to remove. Expected to not be SQL-escaped. 378 * @return bool True, if option is successfully deleted. False on failure. 409 379 */ 410 function delete_blog_option( $id, $ key) {380 function delete_blog_option( $id, $option ) { 411 381 $id = (int) $id; 412 382 413 switch_to_blog($id); 414 $return = delete_option( $key ); 383 if ( $id == get_current_blog_id() ) 384 return delete_option( $option ); 385 386 switch_to_blog( $id ); 387 $return = delete_option( $option ); 415 388 restore_current_blog(); 416 if ( $return ) 417 wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' ); 389 418 390 return $return; 419 391 } 420 392 … … 424 396 * @since MU 425 397 * 426 398 * @param int $id The blog id 427 * @param string $ keyThe option key399 * @param string $option The option key 428 400 * @param mixed $value The option value 429 401 * @return bool True on success, false on failrue. 430 402 */ 431 function update_blog_option( $id, $ key, $value, $deprecated = null ) {403 function update_blog_option( $id, $option, $value, $deprecated = null ) { 432 404 $id = (int) $id; 433 405 434 406 if ( null !== $deprecated ) 435 407 _deprecated_argument( __FUNCTION__, '3.1' ); 436 408 437 switch_to_blog($id); 438 $return = update_option( $key, $value ); 409 if ( $id == get_current_blog_id() ) 410 return update_option( $option, $value ); 411 412 switch_to_blog( $id ); 413 $return = update_option( $option, $value ); 439 414 restore_current_blog(); 440 415 441 416 refresh_blog_details( $id ); 442 417 443 if ( $return )444 wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');445 418 return $return; 446 419 } 447 420