Ticket #10788: options-transients-apis.patch
| File options-transients-apis.patch, 26.9 KB (added by nacin, 3 years ago) |
|---|
-
wp-includes/functions.php
289 289 } 290 290 291 291 /** 292 * Retrieve option value based on settingname.292 * Retrieve option value based on option name. 293 293 * 294 294 * If the option does not exist or does not have a value, then the return value 295 295 * will be false. This is useful to check whether you need to install an option … … 311 311 * @since 1.5.0 312 312 * @package WordPress 313 313 * @subpackage Option 314 * @uses apply_filters() Calls 'pre_option_$option name' false to allow315 * overwritingthe option value in a plugin.316 * @uses apply_filters() Calls 'option_$option name' with the option name value.314 * @uses apply_filters() Calls 'pre_option_$option' null to allow overwriting 315 * the option value in a plugin. 316 * @uses apply_filters() Calls 'option_$option' with the option name value. 317 317 * 318 * @param string $setting Name of option to retrieve. Should already be SQL-escaped 318 * @param string $option Name of option to retrieve. Should already be SQL-escaped 319 * @param mixed $default Optional value to return if option doesn't exist 319 320 * @return mixed Value set for the option. 320 321 */ 321 function get_option( $ setting, $default = false ) {322 function get_option( $option, $default = false ) { 322 323 global $wpdb; 323 324 324 325 // Allow plugins to short-circuit options. 325 $pre = apply_filters( 'pre_option_' . $ setting, false);326 if ( false!== $pre )326 $pre = apply_filters( 'pre_option_' . $option, null ); 327 if ( null !== $pre ) 327 328 return $pre; 328 329 329 330 // prevent non-existent options from triggering multiple queries 330 331 $notoptions = wp_cache_get( 'notoptions', 'options' ); 331 if ( isset( $notoptions[$ setting] ) )332 if ( isset( $notoptions[$option] ) ) 332 333 return $default; 333 334 334 335 $alloptions = wp_load_alloptions(); 335 336 336 if ( isset( $alloptions[$ setting] ) ) {337 $value = $alloptions[$ setting];337 if ( isset( $alloptions[$option] ) ) { 338 $value = $alloptions[$option]; 338 339 } else { 339 $value = wp_cache_get( $ setting, 'options' );340 $value = wp_cache_get( $option, 'options' ); 340 341 341 342 if ( false === $value ) { 342 343 if ( defined( 'WP_INSTALLING' ) ) 343 344 $suppress = $wpdb->suppress_errors(); 344 // expected_slashed ($ setting)345 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$ setting' LIMIT 1" );345 // expected_slashed ($option) 346 $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$option' LIMIT 1" ); 346 347 if ( defined( 'WP_INSTALLING' ) ) 347 348 $wpdb->suppress_errors($suppress); 348 349 349 if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 350 // Has to be get_row instead of get_var because of funkiness with 0, false, null values 351 if ( is_object( $row ) ) { 350 352 $value = $row->option_value; 351 wp_cache_add( $ setting, $value, 'options' );353 wp_cache_add( $option, $value, 'options' ); 352 354 } else { // option does not exist, so we must cache its non-existence 353 $notoptions[$ setting] = true;355 $notoptions[$option] = true; 354 356 wp_cache_set( 'notoptions', $notoptions, 'options' ); 355 357 return $default; 356 358 } … … 358 360 } 359 361 360 362 // If home is not set use siteurl. 361 if ( 'home' == $ setting&& '' == $value )363 if ( 'home' == $option && '' == $value ) 362 364 return get_option( 'siteurl' ); 363 365 364 if ( in_array( $ setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )366 if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) ) 365 367 $value = untrailingslashit( $value ); 366 368 367 return apply_filters( 'option_' . $ setting, maybe_unserialize( $value ) );369 return apply_filters( 'option_' . $option, maybe_unserialize( $value ) ); 368 370 } 369 371 370 372 /** … … 475 477 * to set whether an option autoloaded, then you need to use the add_option(). 476 478 * 477 479 * Before the option is updated, then the filter named 478 * 'pre_update_option_$option _name', with the $option_name as the $option_name479 * parameter value, will be called. The hook should accept two parameters, the480 * first is the new value and the second is the old value. Whatever is481 * returned will be used as the newvalue.480 * 'pre_update_option_$option', with the $option as the $option parameter value, 481 * will be called. The hook should accept two parameters, the first is the new 482 * and the second is the old value. Whatever is returned will be used as the new 483 * value. 482 484 * 483 * After the value has been updated the action named 'update_option_$option _name'485 * After the value has been updated the action named 'update_option_$option' 484 486 * will be called. This action receives two parameters the first being the old 485 487 * value and the second the new value. 486 488 * 487 489 * @since 1.0.0 488 490 * @package WordPress 489 491 * @subpackage Option 492 * @uses apply_filters() calls 'pre_update_option_$option' to allow overwriting 493 * the option value in a plugin. 490 494 * 491 * @param string $option _nameOption name. Expected to not be SQL-escaped492 * @param mixed $ newvalue Option value.495 * @param string $option Option name. Expected to not be SQL-escaped 496 * @param mixed $value Option value. 493 497 * @return bool False if value was not updated and true if value was updated. 494 498 */ 495 function update_option( $option _name, $newvalue ) {499 function update_option( $option, $value ) { 496 500 global $wpdb; 497 501 498 wp_protect_special_option( $option _name);502 wp_protect_special_option( $option ); 499 503 500 $safe_option_name = esc_sql( $option_name ); 501 $newvalue = sanitize_option( $option_name, $newvalue ); 504 $safe_option = esc_sql( $option ); 505 $new_value = sanitize_option( $option, $value ); 506 $old_value = get_option( $safe_option ); 507 $new_value = apply_filters( 'pre_update_option_' . $option, $new_value, $old_value ); 502 508 503 $oldvalue = get_option( $safe_option_name );504 505 $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );506 507 509 // If the new and old values are the same, no need to update. 508 if ( $new value === $oldvalue )510 if ( $new_value === $old_value ) 509 511 return false; 510 512 511 if ( false === $oldvalue ) { 512 add_option( $option_name, $newvalue ); 513 return true; 514 } 513 if ( false === $old_value ) 514 return add_option( $option, $new_value ); 515 515 516 516 $notoptions = wp_cache_get( 'notoptions', 'options' ); 517 if ( is_array( $notoptions ) && isset( $notoptions[$option _name] ) ) {518 unset( $notoptions[$option _name] );517 if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 518 unset( $notoptions[$option] ); 519 519 wp_cache_set( 'notoptions', $notoptions, 'options' ); 520 520 } 521 521 522 $_new value = $newvalue;523 $new value = maybe_serialize( $newvalue );522 $_new_value = $new_value; 523 $new_value = maybe_serialize( $new_value ); 524 524 525 do_action( 'update_option', $option _name, $oldvalue, $newvalue );525 do_action( 'update_option', $option, $old_value, $new_value ); 526 526 $alloptions = wp_load_alloptions(); 527 if ( isset( $alloptions[$option _name] ) ) {528 $alloptions[$option _name] = $newvalue;527 if ( isset( $alloptions[$option] ) ) { 528 $alloptions[$option] = $new_value; 529 529 wp_cache_set( 'alloptions', $alloptions, 'options' ); 530 530 } else { 531 wp_cache_set( $option _name, $newvalue, 'options' );531 wp_cache_set( $option, $new_value, 'options' ); 532 532 } 533 533 534 $wpdb->update($wpdb->options, array('option_value' => $new value), array('option_name' => $option_name) );534 $wpdb->update($wpdb->options, array('option_value' => $new_value), array('option_name' => $option) ); 535 535 536 536 if ( $wpdb->rows_affected == 1 ) { 537 do_action( "update_option_{$option _name}", $oldvalue, $_newvalue );538 do_action( 'updated_option', $option _name, $oldvalue, $_newvalue );537 do_action( "update_option_{$option}", $old_value, $_new_value ); 538 do_action( 'updated_option', $option, $old_value, $_new_value ); 539 539 return true; 540 540 } 541 541 return false; … … 544 544 /** 545 545 * Add a new option. 546 546 * 547 * You do not need to serialize values , if the value needs to be serialize, then547 * You do not need to serialize values. If the value needs to be serialized, then 548 548 * it will be serialized before it is inserted into the database. Remember, 549 549 * resources can not be serialized or added as an option. 550 550 * … … 554 554 * options, the same as the ones which are protected and to not add options 555 555 * that were already added. 556 556 * 557 * The filter named 'add_option_$option name', with the $optionnamebeing557 * The filter named 'add_option_$option', with the $option being 558 558 * replaced with the option's name, will be called. The hook should accept two 559 559 * parameters, the first is the option name, and the second is the value. 560 560 * … … 562 562 * @subpackage Option 563 563 * @since 1.0.0 564 564 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton 565 * @uses apply_filters() Calls 'pre_add_option_$option' to allow overwriting 566 * the option value in a plugin. 565 567 * 566 * @param string $ name Option name to add. Expects to NOTbe SQL escaped.568 * @param string $option Name of option to add. Expects to not be SQL escaped. 567 569 * @param mixed $value Optional. Option value, can be anything. 568 570 * @param mixed $deprecated Optional. Description. Not used anymore. 569 * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.570 * @return null returns when finished.571 * @param bool $autoload Optional. Whether to load the option when WordPress starts up. Default is enabled. 572 * @return bool False if option was not added and true if option was added. 571 573 */ 572 function add_option( $ name, $value = '', $deprecated = '', $autoload = 'yes') {574 function add_option( $option, $value = '', $deprecated = '', $autoload = true ) { 573 575 global $wpdb; 574 576 575 wp_protect_special_option( $name ); 576 $safe_name = esc_sql( $name ); 577 $value = sanitize_option( $name, $value ); 577 wp_protect_special_option( $option ); 578 $safe_name = esc_sql( $option ); 578 579 580 $value = sanitize_option( $option, $value ); 581 $value = apply_filters( 'pre_add_option_' . $option, $value ); 582 579 583 // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 580 584 $notoptions = wp_cache_get( 'notoptions', 'options' ); 581 if ( !is_array( $notoptions ) || !isset( $notoptions[$ name] ) )585 if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) 582 586 if ( false !== get_option( $safe_name ) ) 583 return ;587 return false; 584 588 585 589 $value = maybe_serialize( $value ); 586 $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';587 do_action( 'add_option', $ name, $value );588 if ( 'yes' ==$autoload ) {590 $autoload = ( $autoload && 'no' != $autoload ) ? true : false; 591 do_action( 'add_option', $option, $value ); 592 if ( $autoload ) { 589 593 $alloptions = wp_load_alloptions(); 590 $alloptions[$ name] = $value;594 $alloptions[$option] = $value; 591 595 wp_cache_set( 'alloptions', $alloptions, 'options' ); 592 596 } else { 593 wp_cache_set( $ name, $value, 'options' );597 wp_cache_set( $option, $value, 'options' ); 594 598 } 595 599 596 600 // This option exists now 597 601 $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh 598 if ( is_array( $notoptions ) && isset( $notoptions[$ name] ) ) {599 unset( $notoptions[$ name] );602 if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 603 unset( $notoptions[$option] ); 600 604 wp_cache_set( 'notoptions', $notoptions, 'options' ); 601 605 } 602 606 603 $wpdb->insert($wpdb->options, array('option_name' => $ name, 'option_value' => $value, 'autoload' => $autoload) );607 $wpdb->insert($wpdb->options, array('option_name' => $option, 'option_value' => $value, 'autoload' => ( $autoload ) ? 'yes' : 'no' ) ); 604 608 605 do_action( "add_option_{$ name}", $name, $value );606 do_action( 'added_option', $ name, $value );609 do_action( "add_option_{$option}", $option, $value ); 610 do_action( 'added_option', $option, $value ); 607 611 608 return ;612 return true; 609 613 } 610 614 611 615 /** 612 * Removes option by name and prevents removal of protected WordPress options.616 * Removes option by name. Prevents removal of protected WordPress options. 613 617 * 614 618 * @package WordPress 615 619 * @subpackage Option 616 620 * @since 1.2.0 617 621 * 618 * @param string $ name Option name to remove.622 * @param string $option Name of option to remove. Expected to be SQL-escaped. 619 623 * @return bool True, if succeed. False, if failure. 620 624 */ 621 function delete_option( $ name) {625 function delete_option( $option ) { 622 626 global $wpdb; 623 627 624 wp_protect_special_option( $ name);628 wp_protect_special_option( $option ); 625 629 626 630 // Get the ID, if no ID then return 627 631 // expected_slashed ($name) 628 $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$ name'" );632 $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$option'" ); 629 633 if ( is_null($option) ) 630 634 return false; 631 do_action( 'delete_option', $ name);635 do_action( 'delete_option', $option ); 632 636 // expected_slashed ($name) 633 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$ name'" );637 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$option'" ); 634 638 if ( 'yes' == $option->autoload ) { 635 639 $alloptions = wp_load_alloptions(); 636 if ( isset( $alloptions[$ name] ) ) {637 unset( $alloptions[$ name] );640 if ( isset( $alloptions[$option] ) ) { 641 unset( $alloptions[$option] ); 638 642 wp_cache_set( 'alloptions', $alloptions, 'options' ); 639 643 } 640 644 } else { 641 wp_cache_delete( $ name, 'options' );645 wp_cache_delete( $option, 'options' ); 642 646 } 643 do_action( 'deleted_option', $name ); 647 do_action( "delete_option_{$option}", $option ); 648 do_action( 'deleted_option', $option ); 644 649 return true; 645 650 } 646 651 … … 655 660 * @return bool true if successful, false otherwise 656 661 */ 657 662 function delete_transient($transient) { 658 global $_wp_using_ext_object_cache , $wpdb;663 global $_wp_using_ext_object_cache; 659 664 665 $_transient = $transient; 666 do_action( 'delete_transient', $transient ); 660 667 if ( $_wp_using_ext_object_cache ) { 661 return wp_cache_delete($transient, 'transient');668 $result = wp_cache_delete( $transient, 'transient' ); 662 669 } else { 663 $transient = '_transient_' . esc_sql($transient); 664 return delete_option($transient); 670 $result = delete_option( '_transient_' . esc_sql( $transient ) ); 665 671 } 672 673 if ( $result ) { 674 do_action( "delete_transient_{$transient}", $transient ); 675 do_action( 'deleted_transient', $transient ); 676 } 677 return $result; 666 678 } 667 679 668 680 /** … … 679 691 * @return mixed Value of transient 680 692 */ 681 693 function get_transient($transient) { 682 global $_wp_using_ext_object_cache , $wpdb;694 global $_wp_using_ext_object_cache; 683 695 684 $pre = apply_filters( 'pre_transient_' . $transient, false);685 if ( false!== $pre )696 $pre = apply_filters( 'pre_transient_' . $transient, null ); 697 if ( null !== $pre ) 686 698 return $pre; 687 699 688 700 if ( $_wp_using_ext_object_cache ) { 689 701 $value = wp_cache_get($transient, 'transient'); 690 702 } else { 691 $transient_option = '_transient_' . esc_sql($transient); 703 $safe_transient = esc_sql( $transient ); 704 $transient_option = '_transient_' . $safe_transient; 692 705 // If option is not in alloptions, it is not autoloaded and thus has a timeout 693 706 $alloptions = wp_load_alloptions(); 694 707 if ( !isset( $alloptions[$transient_option] ) ) { 695 $transient_timeout = '_transient_timeout_' . esc_sql($transient);696 if ( get_option( $transient_timeout) < time() ) {697 delete_option( $transient_option);698 delete_option( $transient_timeout);708 $transient_timeout = '_transient_timeout_' . $safe_transient; 709 if ( get_option( $transient_timeout ) < time() ) { 710 delete_option( $transient_option ); 711 delete_option( $transient_timeout ); 699 712 return false; 700 713 } 701 714 } 702 715 703 $value = get_option( $transient_option);716 $value = get_option( $transient_option ); 704 717 } 705 718 706 719 return apply_filters('transient_' . $transient, $value); … … 715 728 * @since 2.8.0 716 729 * @package WordPress 717 730 * @subpackage Transient 731 * @uses apply_filters() Calls 'pre_set_transient_$transient' null to allow overwriting 732 * the transient value in a plugin. 733 * @uses apply_filters() Calls 'pre_set_transient_expiration_$transient' null to allow overwriting 734 * the transient expiration in a plugin. 718 735 * 719 736 * @param string $transient Transient name. Expected to not be SQL-escaped 720 737 * @param mixed $value Transient value. … … 722 739 * @return bool False if value was not set and true if value was set. 723 740 */ 724 741 function set_transient($transient, $value, $expiration = 0) { 725 global $_wp_using_ext_object_cache , $wpdb;742 global $_wp_using_ext_object_cache; 726 743 744 $value = apply_filters( 'pre_set_transient_' . $transient, $value, $expiration ); 745 $expiration = apply_filters( 'pre_set_transient_expiration_' . $transient, $expiration, $value ); 746 747 do_action( 'set_transient', $transient, $value, $expiration ); 727 748 if ( $_wp_using_ext_object_cache ) { 728 returnwp_cache_set($transient, $value, 'transient', $expiration);749 $result = wp_cache_set($transient, $value, 'transient', $expiration); 729 750 } else { 730 751 $transient_timeout = '_transient_timeout_' . $transient; 731 752 $transient = '_transient_' . $transient; … … 734 755 $autoload = 'yes'; 735 756 if ( 0 != $expiration ) { 736 757 $autoload = 'no'; 737 add_option( $transient_timeout, time() + $expiration, '', 'no');758 add_option( $transient_timeout, time() + $expiration, '', 'no' ); 738 759 } 739 return add_option($transient, $value, '', $autoload);760 $result = add_option( $transient, $value, '', $autoload ); 740 761 } else { 741 762 if ( 0 != $expiration ) 742 update_option( $transient_timeout, time() + $expiration);743 return update_option($transient, $value);763 update_option( $transient_timeout, time() + $expiration ); 764 $result = update_option( $transient, $value ); 744 765 } 745 766 } 767 if ( $result ) { 768 do_action( "set_transient_{$transient}", $transient, $value, $expiration ); 769 do_action( 'setted_transient', $transient, $value, $expiration ); 770 } 771 return $result; 746 772 } 747 773 748 774 /** … … 3176 3202 return $current_suspend; 3177 3203 } 3178 3204 3179 function get_site_option( $key, $default = false, $use_cache = true ) { 3205 /** 3206 * Retrieve site option value based on option name. 3207 * 3208 * @see get_option() 3209 * @package WordPress 3210 * @subpackage Option 3211 * @since 2.8.0 3212 * @uses apply_filters() Calls 'pre_site_option_$option' null to allow overwriting 3213 * the option value in a plugin. 3214 * @uses apply_filters() Calls 'site_option_$option' with the option name value. 3215 * 3216 * @param string $option Name of option to retrieve. Should already be SQL-escaped 3217 * @param mixed $default Optional value to return if option doesn't exist 3218 * @param use_cache Used only in WordPress MU. 3219 * @return mixed Value set for the option. 3220 */ 3221 function get_site_option( $option, $default = false, $use_cache = true ) { 3180 3222 // Allow plugins to short-circuit site options. 3181 $pre = apply_filters( 'pre_site_option_' . $ key, false);3182 if ( false!== $pre )3223 $pre = apply_filters( 'pre_site_option_' . $option, null ); 3224 if ( null !== $pre ) 3183 3225 return $pre; 3184 3226 3185 $value = get_option( $key, $default);3227 $value = get_option( $option, $default ) ; 3186 3228 3187 return apply_filters( 'site_option_' . $ key, $value );3229 return apply_filters( 'site_option_' . $option, $value ); 3188 3230 } 3189 3231 3190 // expects $key, $value not to be SQL escaped 3191 function add_site_option( $key, $value ) { 3192 $value = apply_filters( 'pre_add_site_option_' . $key, $value ); 3193 $result = add_option($key, $value); 3194 do_action( "add_site_option_{$key}", $key, $value ); 3232 /** 3233 * Add a new site option. 3234 * 3235 * @see add_option() 3236 * @package WordPress 3237 * @subpackage Option 3238 * @since 2.8.0 3239 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton 3240 * @uses apply_filters() Calls 'pre_add_option_$option' to allow overwriting 3241 * the option value in a plugin. 3242 * 3243 * @param string $option Name of option to add. Expects to not be SQL escaped. 3244 * @param mixed $value Optional. Option value, can be anything. 3245 * @return bool False if option was not added and true if option was added. 3246 */ 3247 function add_site_option( $option, $value ) { 3248 $value = apply_filters( 'pre_add_site_option_' . $option, $value ); 3249 do_action( 'add_site_option', $option, $value ); 3250 $result = add_option( $option, $value ); 3251 if ( $result ) { 3252 do_action( "add_site_option_{$option}", $option, $value ); 3253 do_action( 'added_site_option', $option, $value ); 3254 } 3195 3255 return $result; 3196 3256 } 3197 3257 3198 function delete_site_option( $key ) { 3199 $result = delete_option($key); 3200 do_action( "delete_site_option_{$key}", $key ); 3258 /** 3259 * Removes site option by name. 3260 * 3261 * @see delete_option() 3262 * @package WordPress 3263 * @subpackage Option 3264 * @since 2.8.0 3265 * 3266 * @param string $option Name of option to remove. Expected to be SQL-escaped. 3267 * @return bool True, if succeed. False, if failure. 3268 */ 3269 function delete_site_option( $option ) { 3270 do_action( 'delete_site_option', $option ); 3271 $result = delete_option( $option ); 3272 if ( $result ) { 3273 do_action( "delete_site_option_{$option}", $option ); 3274 do_action( 'deleted_site_option', $option ); 3275 } 3201 3276 return $result; 3202 3277 } 3203 3278 3204 // expects $key, $value not to be SQL escaped 3205 function update_site_option( $key, $value ) { 3206 $oldvalue = get_site_option( $key ); 3207 $value = apply_filters( 'pre_update_site_option_' . $key, $value, $oldvalue ); 3208 $result = update_option($key, $value); 3209 do_action( "update_site_option_{$key}", $key, $value ); 3279 /** 3280 * Update the value of a site option that was already added. 3281 * 3282 * @see update_option() 3283 * @since 2.8.0 3284 * @package WordPress 3285 * @subpackage Option 3286 * @uses apply_filters() calls 'pre_update_site_option_$option' to allow overwriting 3287 * the option value in a plugin. 3288 * 3289 * @param string $option Option name. Expected to not be SQL-escaped 3290 * @param mixed $value Option value. 3291 * @return bool False if value was not updated and true if value was updated. 3292 */ 3293 function update_site_option( $option, $value ) { 3294 $old_value = get_site_option( $option ); 3295 $new_value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value ); 3296 3297 if ( $new_value === $old_value ) 3298 return false; 3299 3300 if ( false === $old_value ) 3301 return add_site_option( $option, $new_value ); 3302 3303 do_action( 'update_site_option', $option, $old_value, $new_value ); 3304 $result = update_option( $option, $new_value ); 3305 if ( $result ) { 3306 do_action( "update_site_option_{$option}", $option, $old_value, $new_value ); 3307 do_action( 'updated_site_option', $option, $old_value, $new_value ); 3308 } 3210 3309 return $result; 3211 3310 } 3212 3311 3213 3312 /** 3214 3313 * Delete a site transient 3215 3314 * 3216 * @since 2.890 3315 * @see delete_transient() 3316 * @since 2.9.0 3217 3317 * @package WordPress 3218 3318 * @subpackage Transient 3219 3319 * … … 3221 3321 * @return bool true if successful, false otherwise 3222 3322 */ 3223 3323 function delete_site_transient($transient) { 3224 global $_wp_using_ext_object_cache , $wpdb;3324 global $_wp_using_ext_object_cache; 3225 3325 3326 do_action( 'delete_site_transient', $transient ); 3226 3327 if ( $_wp_using_ext_object_cache ) { 3227 return wp_cache_delete($transient, 'site-transient');3328 $result = wp_cache_delete( $transient, 'site-transient' ); 3228 3329 } else { 3229 $transient = '_site_transient_' . esc_sql($transient); 3230 return delete_site_option($transient); 3330 $result = delete_site_option( '_site_transient_' . esc_sql( $transient ) ); 3231 3331 } 3332 3333 if ( $result ) { 3334 do_action( "delete_site_transient_{$transient}", $transient ); 3335 do_action( 'deleted_site_transient', $transient ); 3336 } 3337 return $result; 3232 3338 } 3233 3339 3234 3340 /** … … 3237 3343 * If the transient does not exist or does not have a value, then the return value 3238 3344 * will be false. 3239 3345 * 3346 * @see get_transient() 3240 3347 * @since 2.9.0 3241 3348 * @package WordPress 3242 3349 * @subpackage Transient 3350 * @uses apply_filters() calls 'pre_site_transient_$transient' and 'site_transient_$transient' 3351 to allow overwriting the transient value in a plugin. 3243 3352 * 3244 3353 * @param string $transient Transient name. Expected to not be SQL-escaped 3245 3354 * @return mixed Value of transient 3246 3355 */ 3247 3356 function get_site_transient($transient) { 3248 global $_wp_using_ext_object_cache , $wpdb;3357 global $_wp_using_ext_object_cache; 3249 3358 3250 $pre = apply_filters( 'pre_site_transient_' . $transient, false);3251 if ( false!== $pre )3359 $pre = apply_filters( 'pre_site_transient_' . $transient, null ); 3360 if ( null !== $pre ) 3252 3361 return $pre; 3253 3362 3254 3363 if ( $_wp_using_ext_object_cache ) { 3255 $value = wp_cache_get( $transient, 'site-transient');3364 $value = wp_cache_get( $transient, 'site-transient' ); 3256 3365 } else { 3257 $transient_option = '_site_transient_' . esc_sql($transient); 3258 $transient_timeout = '_site_transient_timeout_' . esc_sql($transient); 3259 if ( get_site_option($transient_timeout) < time() ) { 3260 delete_site_option($transient_option); 3261 delete_site_option($transient_timeout); 3366 $safe_transient = esc_sql( $transient ); 3367 $transient_option = '_site_transient_' . $safe_transient; 3368 $transient_timeout = '_site_transient_timeout_' . $safe_transient; 3369 if ( get_site_option( $transient_timeout ) < time() ) { 3370 delete_site_option( $transient_option ); 3371 delete_site_option( $transient_timeout ); 3262 3372 return false; 3263 3373 } 3264 3374 3265 $value = get_site_option( $transient_option);3375 $value = get_site_option( $transient_option ); 3266 3376 } 3267 3377 3268 return apply_filters( 'site_transient_' . $transient, $value);3378 return apply_filters( 'site_transient_' . $transient, $value ); 3269 3379 } 3270 3380 3271 3381 /** … … 3274 3384 * You do not need to serialize values, if the value needs to be serialize, then 3275 3385 * it will be serialized before it is set. 3276 3386 * 3387 * @see set_transient() 3277 3388 * @since 2.9.0 3278 3389 * @package WordPress 3279 3390 * @subpackage Transient 3391 * @uses apply_filters() Calls 'pre_set_site_transient_$transient' null to allow overwriting 3392 * the transient value in a plugin. 3393 * @uses apply_filters() Calls 'pre_set_site_transient_expiration_$transient' null to allow overwriting 3394 * the transient expiration in a plugin. 3280 3395 * 3281 3396 * @param string $transient Transient name. Expected to not be SQL-escaped 3282 3397 * @param mixed $value Transient value. … … 3284 3399 * @return bool False if value was not set and true if value was set. 3285 3400 */ 3286 3401 function set_site_transient($transient, $value, $expiration = 0) { 3287 global $_wp_using_ext_object_cache , $wpdb;3402 global $_wp_using_ext_object_cache; 3288 3403 3404 $value = apply_filters( 'pre_set_site_transient_' . $transient, $value, $expiration ); 3405 $expiration = apply_filters( 'pre_set_site_transient_expiration_' . $transient, $expiration, $value ); 3406 3407 do_action( 'set_site_transient', $transient, $value, $expiration ); 3289 3408 if ( $_wp_using_ext_object_cache ) { 3290 returnwp_cache_set($transient, $value, 'site-transient', $expiration);3409 $result = wp_cache_set($transient, $value, 'site-transient', $expiration); 3291 3410 } else { 3292 3411 $transient_timeout = '_site_transient_timeout_' . $transient; 3293 3412 $transient = '_site_transient_' . $transient; 3294 3413 $safe_transient = esc_sql($transient); 3295 3414 if ( false === get_site_option( $safe_transient ) ) { 3296 3415 if ( 0 != $expiration ) 3297 add_site_option( $transient_timeout, time() + $expiration);3298 returnadd_site_option($transient, $value);3416 add_site_option( $transient_timeout, time() + $expiration ); 3417 $result = add_site_option($transient, $value); 3299 3418 } else { 3300 3419 if ( 0 != $expiration ) 3301 update_site_option( $transient_timeout, time() + $expiration);3302 return update_site_option($transient, $value);3420 update_site_option( $transient_timeout, time() + $expiration ); 3421 $result = update_site_option( $transient, $value ); 3303 3422 } 3304 3423 } 3424 if ( $result ) { 3425 do_action( "set_site_transient_{$transient}", $transient, $value, $expiration ); 3426 do_action( 'setted_site_transient', $transient, $value, $expiration ); 3427 } 3428 return $result; 3305 3429 } 3306 3430 3307 3431 /** … … 3593 3717 function _search_terms_tidy($t) { 3594 3718 return trim($t, "\"\'\n\r "); 3595 3719 } 3596 ?> 3720 ?> 3721 No newline at end of file
