Changeset 13139 for trunk/wp-includes/functions.php
- Timestamp:
- 02/14/2010 06:17:42 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r13102 r13139 312 312 * @package WordPress 313 313 * @subpackage Option 314 * @uses apply_filters() Calls 'pre_option_$option name' false to allow314 * @uses apply_filters() Calls 'pre_option_$option' false to allow 315 315 * overwriting the option value in a plugin. 316 * @uses apply_filters() Calls 'option_$option name' with the option namevalue.317 * 318 * @param string $ settingName of option to retrieve. Should already be SQL-escaped316 * @uses apply_filters() Calls 'option_$option' with the option value. 317 * 318 * @param string $option Name of option to retrieve. Should already be SQL-escaped 319 319 * @return mixed Value set for the option. 320 320 */ 321 function get_option( $ setting, $default = false ) {321 function get_option( $option, $default = false ) { 322 322 global $wpdb; 323 323 324 324 // Allow plugins to short-circuit options. 325 $pre = apply_filters( 'pre_option_' . $ setting, false );325 $pre = apply_filters( 'pre_option_' . $option, false ); 326 326 if ( false !== $pre ) 327 327 return $pre; … … 332 332 } else { 333 333 $notoptions = wp_cache_get( 'notoptions', 'options' ); 334 if ( isset( $notoptions[$ setting] ) )334 if ( isset( $notoptions[$option] ) ) 335 335 return $default; 336 336 } … … 340 340 } 341 341 342 if ( isset( $alloptions[$ setting] ) ) {343 $value = $alloptions[$ setting];342 if ( isset( $alloptions[$option] ) ) { 343 $value = $alloptions[$option]; 344 344 } else { 345 $value = wp_cache_get( $ setting, 'options' );345 $value = wp_cache_get( $option, 'options' ); 346 346 347 347 if ( false === $value ) { 348 348 if ( defined( 'WP_INSTALLING' ) ) 349 349 $suppress = $wpdb->suppress_errors(); 350 // expected_slashed ($ setting)351 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$ setting' LIMIT 1" );350 // expected_slashed ($option) 351 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$option' LIMIT 1" ); 352 352 if ( defined( 'WP_INSTALLING' ) ) 353 $wpdb->suppress_errors( $suppress);353 $wpdb->suppress_errors( $suppress ); 354 354 355 355 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 356 356 $value = $row->option_value; 357 wp_cache_add( $ setting, $value, 'options' );357 wp_cache_add( $option, $value, 'options' ); 358 358 } else { // option does not exist, so we must cache its non-existence 359 $notoptions[$ setting] = true;359 $notoptions[$option] = true; 360 360 wp_cache_set( 'notoptions', $notoptions, 'options' ); 361 361 return $default; … … 365 365 366 366 // If home is not set use siteurl. 367 if ( 'home' == $ setting&& '' == $value )367 if ( 'home' == $option && '' == $value ) 368 368 return get_option( 'siteurl' ); 369 369 370 if ( in_array( $ setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )370 if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) ) 371 371 $value = untrailingslashit( $value ); 372 372 373 return apply_filters( 'option_' . $ setting, maybe_unserialize( $value ) );373 return apply_filters( 'option_' . $option, maybe_unserialize( $value ) ); 374 374 } 375 375 … … 482 482 * 483 483 * Before the option is updated, then the filter named 484 * 'pre_update_option_$option _name', with the $option_name as the $option_name484 * 'pre_update_option_$option', with the $option as the $option 485 485 * parameter value, will be called. The hook should accept two parameters, the 486 486 * first is the new value and the second is the old value. Whatever is 487 487 * returned will be used as the new value. 488 488 * 489 * After the value has been updated the action named 'update_option_$option _name'489 * After the value has been updated the action named 'update_option_$option' 490 490 * will be called. This action receives two parameters the first being the old 491 491 * value and the second the new value. … … 495 495 * @subpackage Option 496 496 * 497 * @param string $option _nameOption name. Expected to not be SQL-escaped497 * @param string $option Option name. Expected to not be SQL-escaped 498 498 * @param mixed $newvalue Option value. 499 499 * @return bool False if value was not updated and true if value was updated. 500 500 */ 501 function update_option( $option _name, $newvalue ) {501 function update_option( $option, $newvalue ) { 502 502 global $wpdb; 503 503 504 wp_protect_special_option( $option _name);505 506 $safe_option_name = esc_sql( $option _name);507 $newvalue = sanitize_option( $option _name, $newvalue );504 wp_protect_special_option( $option ); 505 506 $safe_option_name = esc_sql( $option ); 507 $newvalue = sanitize_option( $option, $newvalue ); 508 508 509 509 $oldvalue = get_option( $safe_option_name ); 510 510 511 $newvalue = apply_filters( 'pre_update_option_' . $option _name, $newvalue, $oldvalue );511 $newvalue = apply_filters( 'pre_update_option_' . $option, $newvalue, $oldvalue ); 512 512 513 513 // If the new and old values are the same, no need to update. … … 515 515 return false; 516 516 517 if ( false === $oldvalue ) { 518 add_option( $option_name, $newvalue ); 519 return true; 520 } 517 if ( false === $oldvalue ) 518 return add_option( $option, $newvalue ); 521 519 522 520 $notoptions = wp_cache_get( 'notoptions', 'options' ); 523 if ( is_array( $notoptions ) && isset( $notoptions[$option _name] ) ) {524 unset( $notoptions[$option _name] );521 if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 522 unset( $notoptions[$option] ); 525 523 wp_cache_set( 'notoptions', $notoptions, 'options' ); 526 524 } … … 529 527 $newvalue = maybe_serialize( $newvalue ); 530 528 531 do_action( 'update_option', $option _name, $oldvalue, $newvalue );529 do_action( 'update_option', $option, $oldvalue, $newvalue ); 532 530 if ( ! defined( 'WP_INSTALLING' ) ) { 533 531 $alloptions = wp_load_alloptions(); 534 if ( isset( $alloptions[$option _name] ) ) {535 $alloptions[$option _name] = $newvalue;532 if ( isset( $alloptions[$option] ) ) { 533 $alloptions[$option] = $newvalue; 536 534 wp_cache_set( 'alloptions', $alloptions, 'options' ); 537 535 } else { 538 wp_cache_set( $option _name, $newvalue, 'options' );536 wp_cache_set( $option, $newvalue, 'options' ); 539 537 } 540 538 } 541 539 542 $ wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );543 544 if ( $ wpdb->rows_affected == 1) {545 do_action( "update_option_{$option _name}", $oldvalue, $_newvalue );546 do_action( 'updated_option', $option _name, $oldvalue, $_newvalue );540 $result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) ); 541 542 if ( $result ) { 543 do_action( "update_option_{$option}", $oldvalue, $_newvalue ); 544 do_action( 'updated_option', $option, $oldvalue, $_newvalue ); 547 545 return true; 548 546 } … … 563 561 * that were already added. 564 562 * 565 * The filter named 'add_option_$option name', with the $optionname being563 * The filter named 'add_option_$option', with the $optionname being 566 564 * replaced with the option's name, will be called. The hook should accept two 567 565 * parameters, the first is the option name, and the second is the value. … … 572 570 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton 573 571 * 574 * @param string $ name Option nameto add. Expects to NOT be SQL escaped.572 * @param string $option Name of option to add. Expects to NOT be SQL escaped. 575 573 * @param mixed $value Optional. Option value, can be anything. 576 574 * @param mixed $deprecated Optional. Description. Not used anymore. … … 578 576 * @return null returns when finished. 579 577 */ 580 function add_option( $ name, $value = '', $deprecated = '', $autoload = 'yes' ) {578 function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { 581 579 if ( !empty( $deprecated ) ) 582 580 _deprecated_argument( __FUNCTION__, '2.3' ); … … 584 582 global $wpdb; 585 583 586 wp_protect_special_option( $ name);587 $safe_name = esc_sql( $ name);588 $value = sanitize_option( $ name, $value );584 wp_protect_special_option( $option ); 585 $safe_name = esc_sql( $option ); 586 $value = sanitize_option( $option, $value ); 589 587 590 588 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 591 589 $notoptions = wp_cache_get( 'notoptions', 'options' ); 592 if ( !is_array( $notoptions ) || !isset( $notoptions[$ name] ) )590 if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) 593 591 if ( false !== get_option( $safe_name ) ) 594 592 return; … … 596 594 $value = maybe_serialize( $value ); 597 595 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; 598 do_action( 'add_option', $ name, $value );596 do_action( 'add_option', $option, $value ); 599 597 if ( ! defined( 'WP_INSTALLING' ) ) { 600 598 if ( 'yes' == $autoload ) { 601 599 $alloptions = wp_load_alloptions(); 602 $alloptions[$ name] = $value;600 $alloptions[$option] = $value; 603 601 wp_cache_set( 'alloptions', $alloptions, 'options' ); 604 602 } else { 605 wp_cache_set( $ name, $value, 'options' );603 wp_cache_set( $option, $value, 'options' ); 606 604 } 607 605 } … … 609 607 // This option exists now 610 608 $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh 611 if ( is_array( $notoptions ) && isset( $notoptions[$ name] ) ) {612 unset( $notoptions[$ name] );609 if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 610 unset( $notoptions[$option] ); 613 611 wp_cache_set( 'notoptions', $notoptions, 'options' ); 614 612 } 615 613 616 $ wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $name, $value, $autoload ) );617 618 do_action( "add_option_{$ name}", $name, $value );619 do_action( 'added_option', $ name, $value );620 621 return ;622 } 623 624 /** 625 * Removes option by name and prevents removal of protected WordPress options.614 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload ) ); 615 616 do_action( "add_option_{$option}", $option, $value ); 617 do_action( 'added_option', $option, $value ); 618 619 return $result; 620 } 621 622 /** 623 * Removes option by name. Prevents removal of protected WordPress options. 626 624 * 627 625 * @package WordPress … … 629 627 * @since 1.2.0 630 628 * 631 * @param string $ name Option nameto remove.629 * @param string $option Name of option to remove. 632 630 * @return bool True, if succeed. False, if failure. 633 631 */ 634 function delete_option( $ name) {632 function delete_option( $option ) { 635 633 global $wpdb; 636 634 637 wp_protect_special_option( $ name);635 wp_protect_special_option( $option ); 638 636 639 637 // Get the ID, if no ID then return 640 // expected_slashed ($ name)641 $ option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" );642 if ( is_null( $option) )638 // expected_slashed ($option) 639 $row = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$option'" ); 640 if ( is_null( $row ) ) 643 641 return false; 644 do_action( 'delete_option', $ name);645 // expected_slashed ($ name)646 $ wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );642 do_action( 'delete_option', $option ); 643 // expected_slashed ($option) 644 $result = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$option'" ); 647 645 if ( ! defined( 'WP_INSTALLING' ) ) { 648 if ( 'yes' == $ option->autoload ) {646 if ( 'yes' == $row->autoload ) { 649 647 $alloptions = wp_load_alloptions(); 650 if ( isset( $alloptions[$ name] ) ) {651 unset( $alloptions[$ name] );648 if ( isset( $alloptions[$option] ) ) { 649 unset( $alloptions[$option] ); 652 650 wp_cache_set( 'alloptions', $alloptions, 'options' ); 653 651 } 654 652 } else { 655 wp_cache_delete( $ name, 'options' );653 wp_cache_delete( $option, 'options' ); 656 654 } 657 655 } 658 do_action( 'deleted_option', $ name);656 do_action( 'deleted_option', $option ); 659 657 return true; 660 658 } … … 670 668 * @return bool true if successful, false otherwise 671 669 */ 672 function delete_transient( $transient) {673 global $_wp_using_ext_object_cache , $wpdb;670 function delete_transient( $transient ) { 671 global $_wp_using_ext_object_cache; 674 672 675 673 do_action( 'delete_transient_' . $transient ); 676 674 677 675 if ( $_wp_using_ext_object_cache ) { 678 return wp_cache_delete( $transient, 'transient');676 return wp_cache_delete( $transient, 'transient' ); 679 677 } else { 680 $transient = '_transient_' . esc_sql( $transient);681 return delete_option( $transient);678 $transient = '_transient_' . esc_sql( $transient ); 679 return delete_option( $transient ); 682 680 } 683 681 } … … 696 694 * @return mixed Value of transient 697 695 */ 698 function get_transient( $transient) {699 global $_wp_using_ext_object_cache , $wpdb;696 function get_transient( $transient ) { 697 global $_wp_using_ext_object_cache; 700 698 701 699 $pre = apply_filters( 'pre_transient_' . $transient, false ); … … 704 702 705 703 if ( $_wp_using_ext_object_cache ) { 706 $value = wp_cache_get( $transient, 'transient');704 $value = wp_cache_get( $transient, 'transient' ); 707 705 } else { 708 $transient_option = '_transient_' . esc_sql($transient); 706 $safe_transient = esc_sql( $transient ); 707 $transient_option = '_transient_' . $safe_transient; 709 708 if ( ! defined( 'WP_INSTALLING' ) ) { 710 709 // If option is not in alloptions, it is not autoloaded and thus has a timeout 711 710 $alloptions = wp_load_alloptions(); 712 711 if ( !isset( $alloptions[$transient_option] ) ) { 713 $transient_timeout = '_transient_timeout_' . esc_sql($transient);714 if ( get_option( $transient_timeout) < time() ) {715 delete_option( $transient_option);716 delete_option( $transient_timeout);712 $transient_timeout = '_transient_timeout_' . $safe_transient; 713 if ( get_option( $transient_timeout ) < time() ) { 714 delete_option( $transient_option ); 715 delete_option( $transient_timeout ); 717 716 return false; 718 717 } … … 720 719 } 721 720 722 $value = get_option( $transient_option);723 } 724 725 return apply_filters( 'transient_' . $transient, $value);721 $value = get_option( $transient_option ); 722 } 723 724 return apply_filters( 'transient_' . $transient, $value ); 726 725 } 727 726 … … 729 728 * Set/update the value of a transient 730 729 * 731 * You do not need to serialize values , if the value needs to be serialize, then730 * You do not need to serialize values. If the value needs to be serialized, then 732 731 * it will be serialized before it is set. 733 732 * … … 741 740 * @return bool False if value was not set and true if value was set. 742 741 */ 743 function set_transient( $transient, $value, $expiration = 0) {744 global $_wp_using_ext_object_cache , $wpdb;742 function set_transient( $transient, $value, $expiration = 0 ) { 743 global $_wp_using_ext_object_cache; 745 744 746 745 $value = apply_filters( 'pre_set_transient_' . $transient, $value ); 747 746 748 747 if ( $_wp_using_ext_object_cache ) { 749 return wp_cache_set( $transient, $value, 'transient', $expiration);748 return wp_cache_set( $transient, $value, 'transient', $expiration ); 750 749 } else { 751 750 $transient_timeout = '_transient_timeout_' . $transient; 752 751 $transient = '_transient_' . $transient; 753 $safe_transient = esc_sql( $transient);752 $safe_transient = esc_sql( $transient ); 754 753 if ( false === get_option( $safe_transient ) ) { 755 754 $autoload = 'yes'; 756 if ( 0 !=$expiration ) {755 if ( $expiration ) { 757 756 $autoload = 'no'; 758 757 add_option($transient_timeout, time() + $expiration, '', 'no'); … … 760 759 return add_option($transient, $value, '', $autoload); 761 760 } else { 762 if ( 0 !=$expiration )763 update_option( $transient_timeout, time() + $expiration);761 if ( $expiration ) 762 update_option( $transient_timeout, time() + $expiration ); 764 763 return update_option($transient, $value); 765 764 } … … 3343 3342 3344 3343 /** 3345 * {@internal Missing Short Description}} 3346 * 3347 * @since 2.8 3348 * 3349 * @param unknown_type $key 3350 * @param unknown_type $default 3351 * @param unknown_type $use_cache 3352 * @return unknown 3353 */ 3354 function get_site_option( $key, $default = false, $use_cache = true ) { 3344 * Retrieve site option value based on name of option. 3345 * 3346 * @see get_option() 3347 * @package WordPress 3348 * @subpackage Option 3349 * @since 2.8.0 3350 * 3351 * @param string $option Name of option to retrieve. Should already be SQL-escaped 3352 * @param mixed $default Optional value to return if option doesn't exist. Default false. 3353 * @param bool $use_cache Whether to use cache. Multisite only. Default true. 3354 * @return mixed Value set for the option. 3355 */ 3356 function get_site_option( $option, $default = false, $use_cache = true ) { 3355 3357 global $wpdb; 3356 3358 3357 3359 // Allow plugins to short-circuit site options. 3358 $pre = apply_filters( 'pre_site_option_' . $ key, false );3360 $pre = apply_filters( 'pre_site_option_' . $option, false ); 3359 3361 if ( false !== $pre ) 3360 3362 return $pre; 3361 3363 3362 3364 if ( !is_multisite() ) { 3363 $value = get_option($ key, $default);3365 $value = get_option($option, $default); 3364 3366 } else { 3365 $cache_key = " $wpdb->siteid:$key";3367 $cache_key = "{$wpdb->siteid}:$option"; 3366 3368 if ( $use_cache ) 3367 3369 $value = wp_cache_get($cache_key, 'site-options'); 3368 3370 3369 3371 if ( false === $value ) { 3370 $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $ key, $wpdb->siteid) );3372 $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); 3371 3373 3372 3374 if ( is_null($value) ) … … 3379 3381 } 3380 3382 3381 return apply_filters( 'site_option_' . $key, $value ); 3382 } 3383 3384 /** 3385 * {@internal Missing Short Description}} 3386 * 3387 * @since 2.8 3388 * 3389 * @param unknown_type $key not to be SQL escaped 3390 * @param unknown_type $value not to be SQL escaped 3391 * @return unknown 3392 */ 3393 function add_site_option( $key, $value ) { 3383 return apply_filters( 'site_option_' . $option, $value ); 3384 } 3385 3386 /** 3387 * Add a new site option. 3388 * 3389 * @see add_option() 3390 * @package WordPress 3391 * @subpackage Option 3392 * @since 2.8.0 3393 * 3394 * @param string $option Name of option to add. Expects to not be SQL escaped. 3395 * @param mixed $value Optional. Option value, can be anything. 3396 * @return bool False if option was not added and true if option was added. 3397 */ 3398 function add_site_option( $option, $value ) { 3394 3399 global $wpdb; 3395 3400 3396 $value = apply_filters( 'pre_add_site_option_' . $ key, $value );3401 $value = apply_filters( 'pre_add_site_option_' . $option, $value ); 3397 3402 3398 3403 if ( !is_multisite() ) { 3399 $result = add_option($key, $value);3404 $result = add_option( $option, $value ); 3400 3405 } else { 3401 $cache_key = "{$wpdb->siteid}:$ key";3402 3403 if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $ key, $wpdb->siteid ) ) )3404 return update_site_option( $ key, $value );3405 3406 $value = sanitize_option( $ key, $value );3407 wp_cache_set( $cache_key, $value, 'site-options' );3406 $cache_key = "{$wpdb->siteid}:$option"; 3407 3408 if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) 3409 return update_site_option( $option, $value ); 3410 3411 $value = sanitize_option( $option, $value ); 3412 wp_cache_set( $cache_key, $value, 'site-options' ); 3408 3413 3409 3414 $value = maybe_serialize($value); 3410 3415 3411 $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $ key, 'meta_value' => $value) );3412 } 3413 3414 do_action( "add_site_option_{$ key}", $key, $value );3415 do_action( "add_site_option", $ key, $value );3416 $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) ); 3417 } 3418 3419 do_action( "add_site_option_{$option}", $option, $value ); 3420 do_action( "add_site_option", $option, $value ); 3416 3421 3417 3422 return $result; … … 3419 3424 3420 3425 /** 3421 * {@internal Missing Short Description}} 3422 * 3423 * @since 2.9 3424 * 3425 * @param unknown_type $key 3426 * @return unknown 3427 */ 3428 function delete_site_option( $key ) { 3426 * Removes site option by name. 3427 * 3428 * @see delete_option() 3429 * @package WordPress 3430 * @subpackage Option 3431 * @since 2.8.0 3432 * 3433 * @param string $option Name of option to remove. Expected to be SQL-escaped. 3434 * @return bool True, if succeed. False, if failure. 3435 */ 3436 function delete_site_option( $option ) { 3429 3437 global $wpdb; 3430 3438 3431 // wpmu_protect_special_option( $key); @todo3432 3433 do_action( 'pre_delete_site_option_' . $ key);3439 // ms_protect_special_option( $option ); @todo 3440 3441 do_action( 'pre_delete_site_option_' . $option ); 3434 3442 3435 3443 if ( !is_multisite() ) { 3436 $result = delete_option( $key);3444 $result = delete_option( $option ); 3437 3445 } else { 3438 $option = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $ key, $wpdb->siteid ) );3446 $option = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); 3439 3447 if ( is_null( $option ) || !$option->meta_id ) 3440 3448 return false; 3441 $cache_key = "{$wpdb->siteid}:$ key";3449 $cache_key = "{$wpdb->siteid}:$option"; 3442 3450 wp_cache_delete( $cache_key, 'site-options' ); 3443 3451 3444 $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $ key, $wpdb->siteid ) );3445 } 3446 3447 do_action( "delete_site_option_{$ key}", $key);3448 do_action( "delete_site_option", $ key);3452 $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); 3453 } 3454 3455 do_action( "delete_site_option_{$option}", $option ); 3456 do_action( "delete_site_option", $option ); 3449 3457 return $result; 3450 3458 } 3451 3459 3452 3460 /** 3453 * {@internal Missing Short Description}} 3454 * 3461 * Update the value of a site option that was already added. 3462 * 3463 * @see update_option() 3455 3464 * @since 2.8.0 3456 * 3457 * @param unknown_type $key not to be SQL escaped 3458 * @param unknown_type $value not to be SQL escaped 3459 * @return unknown 3460 */ 3461 function update_site_option( $key, $value ) { 3465 * @package WordPress 3466 * @subpackage Option 3467 * 3468 * @param string $option Name of option. Expected to not be SQL-escaped 3469 * @param mixed $value Option value. 3470 * @return bool False if value was not updated and true if value was updated. 3471 */ 3472 function update_site_option( $option, $value ) { 3462 3473 global $wpdb; 3463 3474 3464 $oldvalue = get_site_option( $ key);3465 $value = apply_filters( 'pre_update_site_option_' . $ key, $value, $oldvalue );3466 3467 if ( $value == $oldvalue )3475 $oldvalue = get_site_option( $option ); 3476 $value = apply_filters( 'pre_update_site_option_' . $option, $value, $oldvalue ); 3477 3478 if ( $value === $oldvalue ) 3468 3479 return false; 3469 3480 3470 3481 if ( !is_multisite() ) { 3471 $result = update_option( $key, $value);3482 $result = update_option( $option, $value ); 3472 3483 } else { 3473 $cache_key = "{$wpdb->siteid}:$ key";3474 3475 if ( $value && !$wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ) )3476 return add_site_option( $ key, $value );3477 $value = sanitize_option( $ key, $value );3484 $cache_key = "{$wpdb->siteid}:$option"; 3485 3486 if ( $value && !$wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) 3487 return add_site_option( $option, $value ); 3488 $value = sanitize_option( $option, $value ); 3478 3489 wp_cache_set( $cache_key, $value, 'site-options' ); 3479 3490 3480 $value = maybe_serialize( $value);3481 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $value), array('site_id' => $wpdb->siteid, 'meta_key' => $key) );3482 } 3483 3484 do_action( "update_site_option_{$ key}", $key, $value );3485 do_action( "update_site_option", $ key, $value );3491 $value = maybe_serialize( $value ); 3492 $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) ); 3493 } 3494 3495 do_action( "update_site_option_{$option}", $option, $value ); 3496 do_action( "update_site_option", $option, $value ); 3486 3497 return $result; 3487 3498 } … … 3495 3506 * 3496 3507 * @param string $transient Transient name. Expected to not be SQL-escaped 3497 * @return bool true if successful, false otherwise3498 */ 3499 function delete_site_transient( $transient) {3500 global $_wp_using_ext_object_cache , $wpdb;3508 * @return bool True if successful, false otherwise 3509 */ 3510 function delete_site_transient( $transient ) { 3511 global $_wp_using_ext_object_cache; 3501 3512 3502 3513 if ( $_wp_using_ext_object_cache ) { 3503 return wp_cache_delete($transient, 'site-transient');3514 $result = wp_cache_delete( $transient, 'site-transient' ); 3504 3515 } else { 3505 $transient = '_site_transient_' . esc_sql($transient); 3506 return delete_site_option($transient); 3507 } 3516 $transient = '_site_transient_' . esc_sql( $transient ); 3517 $result = delete_site_option( $transient ); 3518 } 3519 return $result; 3508 3520 } 3509 3521 … … 3514 3526 * will be false. 3515 3527 * 3528 * @see get_transient() 3516 3529 * @since 2.9.0 3517 3530 * @package WordPress … … 3521 3534 * @return mixed Value of transient 3522 3535 */ 3523 function get_site_transient( $transient) {3524 global $_wp_using_ext_object_cache , $wpdb;3536 function get_site_transient( $transient ) { 3537 global $_wp_using_ext_object_cache; 3525 3538 3526 3539 $pre = apply_filters( 'pre_site_transient_' . $transient, false ); … … 3529 3542 3530 3543 if ( $_wp_using_ext_object_cache ) { 3531 $value = wp_cache_get( $transient, 'site-transient');3544 $value = wp_cache_get( $transient, 'site-transient' ); 3532 3545 } else { 3533 3546 // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. 3534 3547 $no_timeout = array('update_core', 'update_plugins', 'update_themes'); 3535 $transient_option = '_site_transient_' . esc_sql( $transient);3536 if ( ! in_array($transient, $no_timeout) ) {3537 $transient_timeout = '_site_transient_timeout_' . esc_sql( $transient);3538 $timeout = get_site_option( $transient_timeout);3548 $transient_option = '_site_transient_' . esc_sql( $transient ); 3549 if ( ! in_array( $transient, $no_timeout ) ) { 3550 $transient_timeout = '_site_transient_timeout_' . esc_sql( $transient ); 3551 $timeout = get_site_option( $transient_timeout ); 3539 3552 if ( false !== $timeout && $timeout < time() ) { 3540 delete_site_option( $transient_option);3541 delete_site_option( $transient_timeout);3553 delete_site_option( $transient_option ); 3554 delete_site_option( $transient_timeout ); 3542 3555 return false; 3543 3556 } 3544 3557 } 3545 3558 3546 $value = get_site_option( $transient_option);3547 } 3548 3549 return apply_filters( 'site_transient_' . $transient, $value);3559 $value = get_site_option( $transient_option ); 3560 } 3561 3562 return apply_filters( 'site_transient_' . $transient, $value ); 3550 3563 } 3551 3564 … … 3556 3569 * it will be serialized before it is set. 3557 3570 * 3571 * @see set_transient() 3558 3572 * @since 2.9.0 3559 3573 * @package WordPress … … 3565 3579 * @return bool False if value was not set and true if value was set. 3566 3580 */ 3567 function set_site_transient( $transient, $value, $expiration = 0) {3568 global $_wp_using_ext_object_cache , $wpdb;3581 function set_site_transient( $transient, $value, $expiration = 0 ) { 3582 global $_wp_using_ext_object_cache; 3569 3583 3570 3584 if ( $_wp_using_ext_object_cache ) { 3571 return wp_cache_set($transient, $value, 'site-transient', $expiration);3585 $result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); 3572 3586 } else { 3573 3587 $transient_timeout = '_site_transient_timeout_' . $transient; 3574 3588 $transient = '_site_transient_' . $transient; 3575 $safe_transient = esc_sql( $transient);3589 $safe_transient = esc_sql( $transient ); 3576 3590 if ( false === get_site_option( $safe_transient ) ) { 3577 if ( 0 !=$expiration )3578 add_site_option( $transient_timeout, time() + $expiration);3579 return add_site_option($transient, $value);3591 if ( $expiration ) 3592 add_site_option( $transient_timeout, time() + $expiration ); 3593 $result = add_site_option( $transient, $value ); 3580 3594 } else { 3581 if ( 0 !=$expiration )3582 update_site_option( $transient_timeout, time() + $expiration);3583 return update_site_option($transient, $value);3595 if ( $expiration ) 3596 update_site_option( $transient_timeout, time() + $expiration ); 3597 $result = update_site_option( $transient, $value ); 3584 3598 } 3585 3599 } 3600 return $result; 3586 3601 } 3587 3602
Note: See TracChangeset
for help on using the changeset viewer.