WordPress.org

Make WordPress Core

Ticket #10788: options-transients-apis.patch

File options-transients-apis.patch, 26.9 KB (added by nacin, 8 years ago)

Actual first pass on potential overhaul of options/transients.

  • wp-includes/functions.php

     
    289289}
    290290
    291291/**
    292  * Retrieve option value based on setting name.
     292 * Retrieve option value based on option name.
    293293 *
    294294 * If the option does not exist or does not have a value, then the return value
    295295 * will be false. This is useful to check whether you need to install an option
     
    311311 * @since 1.5.0
    312312 * @package WordPress
    313313 * @subpackage Option
    314  * @uses apply_filters() Calls 'pre_option_$optionname' false to allow
    315  *              overwriting the option value in a plugin.
    316  * @uses apply_filters() Calls 'option_$optionname' 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.
    317317 *
    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
    319320 * @return mixed Value set for the option.
    320321 */
    321 function get_option( $setting, $default = false ) {
     322function get_option( $option, $default = false ) {
    322323        global $wpdb;
    323324
    324325        // 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 )
    327328                return $pre;
    328329
    329330        // prevent non-existent options from triggering multiple queries
    330331        $notoptions = wp_cache_get( 'notoptions', 'options' );
    331         if ( isset( $notoptions[$setting] ) )
     332        if ( isset( $notoptions[$option] ) )
    332333                return $default;
    333334
    334335        $alloptions = wp_load_alloptions();
    335336
    336         if ( isset( $alloptions[$setting] ) ) {
    337                 $value = $alloptions[$setting];
     337        if ( isset( $alloptions[$option] ) ) {
     338                $value = $alloptions[$option];
    338339        } else {
    339                 $value = wp_cache_get( $setting, 'options' );
     340                $value = wp_cache_get( $option, 'options' );
    340341
    341342                if ( false === $value ) {
    342343                        if ( defined( 'WP_INSTALLING' ) )
    343344                                $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" );
    346347                        if ( defined( 'WP_INSTALLING' ) )
    347348                                $wpdb->suppress_errors($suppress);
    348349
    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 ) ) {
    350352                                $value = $row->option_value;
    351                                 wp_cache_add( $setting, $value, 'options' );
     353                                wp_cache_add( $option, $value, 'options' );
    352354                        } else { // option does not exist, so we must cache its non-existence
    353                                 $notoptions[$setting] = true;
     355                                $notoptions[$option] = true;
    354356                                wp_cache_set( 'notoptions', $notoptions, 'options' );
    355357                                return $default;
    356358                        }
     
    358360        }
    359361
    360362        // If home is not set use siteurl.
    361         if ( 'home' == $setting && '' == $value )
     363        if ( 'home' == $option && '' == $value )
    362364                return get_option( 'siteurl' );
    363365
    364         if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
     366        if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
    365367                $value = untrailingslashit( $value );
    366368
    367         return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
     369        return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );
    368370}
    369371
    370372/**
     
    475477 * to set whether an option autoloaded, then you need to use the add_option().
    476478 *
    477479 * Before the option is updated, then the filter named
    478  * 'pre_update_option_$option_name', with the $option_name as the $option_name
    479  * parameter value, will be called. The hook should accept two parameters, the
    480  * first is the new value and the second is the old value.  Whatever is
    481  * returned will be used as the new value.
     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.
    482484 *
    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'
    484486 * will be called.  This action receives two parameters the first being the old
    485487 * value and the second the new value.
    486488 *
    487489 * @since 1.0.0
    488490 * @package WordPress
    489491 * @subpackage Option
     492 * @uses apply_filters() calls 'pre_update_option_$option' to allow overwriting
     493 *   the option value in a plugin.
    490494 *
    491  * @param string $option_name Option name. Expected to not be SQL-escaped
    492  * @param mixed $newvalue Option value.
     495 * @param string $option Option name. Expected to not be SQL-escaped
     496 * @param mixed $value Option value.
    493497 * @return bool False if value was not updated and true if value was updated.
    494498 */
    495 function update_option( $option_name, $newvalue ) {
     499function update_option( $option, $value ) {
    496500        global $wpdb;
    497501
    498         wp_protect_special_option( $option_name );
     502        wp_protect_special_option( $option );
    499503
    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 );
    502508
    503         $oldvalue = get_option( $safe_option_name );
    504 
    505         $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
    506 
    507509        // If the new and old values are the same, no need to update.
    508         if ( $newvalue === $oldvalue )
     510        if ( $new_value === $old_value )
    509511                return false;
    510512
    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 );
    515515
    516516        $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] );
    519519                wp_cache_set( 'notoptions', $notoptions, 'options' );
    520520        }
    521521
    522         $_newvalue = $newvalue;
    523         $newvalue = maybe_serialize( $newvalue );
     522        $_new_value = $new_value;
     523        $new_value  = maybe_serialize( $new_value );
    524524
    525         do_action( 'update_option', $option_name, $oldvalue, $newvalue );
     525        do_action( 'update_option', $option, $old_value, $new_value );
    526526        $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;
    529529                wp_cache_set( 'alloptions', $alloptions, 'options' );
    530530        } else {
    531                 wp_cache_set( $option_name, $newvalue, 'options' );
     531                wp_cache_set( $option, $new_value, 'options' );
    532532        }
    533533
    534         $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
     534        $wpdb->update($wpdb->options, array('option_value' => $new_value), array('option_name' => $option) );
    535535
    536536        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 );
    539539                return true;
    540540        }
    541541        return false;
     
    544544/**
    545545 * Add a new option.
    546546 *
    547  * You do not need to serialize values, if the value needs to be serialize, then
     547 * You do not need to serialize values. If the value needs to be serialized, then
    548548 * it will be serialized before it is inserted into the database. Remember,
    549549 * resources can not be serialized or added as an option.
    550550 *
     
    554554 * options, the same as the ones which are protected and to not add options
    555555 * that were already added.
    556556 *
    557  * The filter named 'add_option_$optionname', with the $optionname being
     557 * The filter named 'add_option_$option', with the $option being
    558558 * replaced with the option's name, will be called. The hook should accept two
    559559 * parameters, the first is the option name, and the second is the value.
    560560 *
     
    562562 * @subpackage Option
    563563 * @since 1.0.0
    564564 * @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.
    565567 *
    566  * @param string $name Option name to add. Expects to NOT be SQL escaped.
     568 * @param string $option Name of option to add. Expects to not be SQL escaped.
    567569 * @param mixed $value Optional. Option value, can be anything.
    568570 * @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.
    571573 */
    572 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
     574function add_option( $option, $value = '', $deprecated = '', $autoload = true ) {
    573575        global $wpdb;
    574576
    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 );
    578579
     580        $value = sanitize_option( $option, $value );
     581        $value = apply_filters( 'pre_add_option_' . $option, $value );
     582
    579583        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    580584        $notoptions = wp_cache_get( 'notoptions', 'options' );
    581         if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
     585        if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
    582586                if ( false !== get_option( $safe_name ) )
    583                         return;
     587                        return false;
    584588
    585589        $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 ) {
    589593                $alloptions = wp_load_alloptions();
    590                 $alloptions[$name] = $value;
     594                $alloptions[$option] = $value;
    591595                wp_cache_set( 'alloptions', $alloptions, 'options' );
    592596        } else {
    593                 wp_cache_set( $name, $value, 'options' );
     597                wp_cache_set( $option, $value, 'options' );
    594598        }
    595599
    596600        // This option exists now
    597601        $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] );
    600604                wp_cache_set( 'notoptions', $notoptions, 'options' );
    601605        }
    602606
    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' ) );
    604608
    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 );
    607611       
    608         return;
     612        return true;
    609613}
    610614
    611615/**
    612  * Removes option by name and prevents removal of protected WordPress options.
     616 * Removes option by name. Prevents removal of protected WordPress options.
    613617 *
    614618 * @package WordPress
    615619 * @subpackage Option
    616620 * @since 1.2.0
    617621 *
    618  * @param string $name Option name to remove.
     622 * @param string $option Name of option to remove. Expected to be SQL-escaped.
    619623 * @return bool True, if succeed. False, if failure.
    620624 */
    621 function delete_option( $name ) {
     625function delete_option( $option ) {
    622626        global $wpdb;
    623627
    624         wp_protect_special_option( $name );
     628        wp_protect_special_option( $option );
    625629
    626630        // Get the ID, if no ID then return
    627631        // 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'" );
    629633        if ( is_null($option) )
    630634                return false;
    631         do_action( 'delete_option', $name );
     635        do_action( 'delete_option', $option );
    632636        // 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'" );
    634638        if ( 'yes' == $option->autoload ) {
    635639                $alloptions = wp_load_alloptions();
    636                 if ( isset( $alloptions[$name] ) ) {
    637                         unset( $alloptions[$name] );
     640                if ( isset( $alloptions[$option] ) ) {
     641                        unset( $alloptions[$option] );
    638642                        wp_cache_set( 'alloptions', $alloptions, 'options' );
    639643                }
    640644        } else {
    641                 wp_cache_delete( $name, 'options' );
     645                wp_cache_delete( $option, 'options' );
    642646        }
    643         do_action( 'deleted_option', $name );
     647        do_action( "delete_option_{$option}", $option );
     648        do_action( 'deleted_option', $option );
    644649        return true;
    645650}
    646651
     
    655660 * @return bool true if successful, false otherwise
    656661 */
    657662function delete_transient($transient) {
    658         global $_wp_using_ext_object_cache, $wpdb;
     663        global $_wp_using_ext_object_cache;
    659664
     665        $_transient = $transient;
     666        do_action( 'delete_transient', $transient );
    660667        if ( $_wp_using_ext_object_cache ) {
    661                 return wp_cache_delete($transient, 'transient');
     668                $result = wp_cache_delete( $transient, 'transient' );
    662669        } else {
    663                 $transient = '_transient_' . esc_sql($transient);
    664                 return delete_option($transient);
     670                $result = delete_option( '_transient_' . esc_sql( $transient ) );
    665671        }
     672
     673        if ( $result ) {
     674                do_action( "delete_transient_{$transient}", $transient );
     675                do_action( 'deleted_transient', $transient );
     676        }
     677        return $result;
    666678}
    667679
    668680/**
     
    679691 * @return mixed Value of transient
    680692 */
    681693function get_transient($transient) {
    682         global $_wp_using_ext_object_cache, $wpdb;
     694        global $_wp_using_ext_object_cache;
    683695
    684         $pre = apply_filters( 'pre_transient_' . $transient, false );
    685         if ( false !== $pre )
     696        $pre = apply_filters( 'pre_transient_' . $transient, null );
     697        if ( null !== $pre )
    686698                return $pre;
    687699
    688700        if ( $_wp_using_ext_object_cache ) {
    689701                $value = wp_cache_get($transient, 'transient');
    690702        } else {
    691                 $transient_option = '_transient_' . esc_sql($transient);
     703                $safe_transient = esc_sql( $transient );
     704                $transient_option = '_transient_' . $safe_transient;
    692705                // If option is not in alloptions, it is not autoloaded and thus has a timeout
    693706                $alloptions = wp_load_alloptions();
    694707                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 );
    699712                                return false;
    700713                        }
    701714                }
    702715
    703                 $value = get_option($transient_option);
     716                $value = get_option( $transient_option );
    704717        }
    705718
    706719        return apply_filters('transient_' . $transient, $value);
     
    715728 * @since 2.8.0
    716729 * @package WordPress
    717730 * @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.
    718735 *
    719736 * @param string $transient Transient name. Expected to not be SQL-escaped
    720737 * @param mixed $value Transient value.
     
    722739 * @return bool False if value was not set and true if value was set.
    723740 */
    724741function set_transient($transient, $value, $expiration = 0) {
    725         global $_wp_using_ext_object_cache, $wpdb;
     742        global $_wp_using_ext_object_cache;
    726743
     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 );
    727748        if ( $_wp_using_ext_object_cache ) {
    728                 return wp_cache_set($transient, $value, 'transient', $expiration);
     749                $result = wp_cache_set($transient, $value, 'transient', $expiration);
    729750        } else {
    730751                $transient_timeout = '_transient_timeout_' . $transient;
    731752                $transient = '_transient_' . $transient;
     
    734755                        $autoload = 'yes';
    735756                        if ( 0 != $expiration ) {
    736757                                $autoload = 'no';
    737                                 add_option($transient_timeout, time() + $expiration, '', 'no');
     758                                add_option( $transient_timeout, time() + $expiration, '', 'no' );
    738759                        }
    739                         return add_option($transient, $value, '', $autoload);
     760                        $result = add_option( $transient, $value, '', $autoload );
    740761                } else {
    741762                        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 );
    744765                }
    745766        }
     767        if ( $result ) {
     768                do_action( "set_transient_{$transient}", $transient, $value, $expiration );
     769                do_action( 'setted_transient', $transient, $value, $expiration );
     770        }
     771        return $result;
    746772}
    747773
    748774/**
     
    31763202        return $current_suspend;
    31773203}
    31783204
    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 */
     3221function get_site_option( $option, $default = false, $use_cache = true ) {
    31803222        // 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 )
    31833225                return $pre;
    31843226
    3185         $value = get_option($key, $default);
     3227        $value = get_option( $option, $default ) ;
    31863228
    3187         return apply_filters( 'site_option_' . $key, $value );
     3229        return apply_filters( 'site_option_' . $option, $value );
    31883230}
    31893231
    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 */
     3247function 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        }
    31953255        return $result;
    31963256}
    31973257
    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 */
     3269function 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        }
    32013276        return $result;
    32023277}
    32033278
    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 */
     3293function 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        }
    32103309        return $result;
    32113310}
    32123311
    32133312/**
    32143313 * Delete a site transient
    32153314 *
    3216  * @since 2.890
     3315 * @see delete_transient()
     3316 * @since 2.9.0
    32173317 * @package WordPress
    32183318 * @subpackage Transient
    32193319 *
     
    32213321 * @return bool true if successful, false otherwise
    32223322 */
    32233323function delete_site_transient($transient) {
    3224         global $_wp_using_ext_object_cache, $wpdb;
     3324        global $_wp_using_ext_object_cache;
    32253325
     3326        do_action( 'delete_site_transient', $transient );
    32263327        if ( $_wp_using_ext_object_cache ) {
    3227                 return wp_cache_delete($transient, 'site-transient');
     3328                $result = wp_cache_delete( $transient, 'site-transient' );
    32283329        } else {
    3229                 $transient = '_site_transient_' . esc_sql($transient);
    3230                 return delete_site_option($transient);
     3330                $result = delete_site_option( '_site_transient_' . esc_sql( $transient ) );
    32313331        }
     3332
     3333        if ( $result ) {
     3334                do_action( "delete_site_transient_{$transient}", $transient );
     3335                do_action( 'deleted_site_transient', $transient );
     3336        }
     3337        return $result;
    32323338}
    32333339
    32343340/**
     
    32373343 * If the transient does not exist or does not have a value, then the return value
    32383344 * will be false.
    32393345 *
     3346 * @see get_transient()
    32403347 * @since 2.9.0
    32413348 * @package WordPress
    32423349 * @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.
    32433352 *
    32443353 * @param string $transient Transient name. Expected to not be SQL-escaped
    32453354 * @return mixed Value of transient
    32463355 */
    32473356function get_site_transient($transient) {
    3248         global $_wp_using_ext_object_cache, $wpdb;
     3357        global $_wp_using_ext_object_cache;
    32493358
    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 )
    32523361                return $pre;
    32533362
    32543363        if ( $_wp_using_ext_object_cache ) {
    3255                 $value = wp_cache_get($transient, 'site-transient');
     3364                $value = wp_cache_get( $transient, 'site-transient' );
    32563365        } 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 );
    32623372                        return false;
    32633373                }
    32643374
    3265                 $value = get_site_option($transient_option);
     3375                $value = get_site_option( $transient_option );
    32663376        }
    32673377
    3268         return apply_filters('site_transient_' . $transient, $value);
     3378        return apply_filters( 'site_transient_' . $transient, $value );
    32693379}
    32703380
    32713381/**
     
    32743384 * You do not need to serialize values, if the value needs to be serialize, then
    32753385 * it will be serialized before it is set.
    32763386 *
     3387 * @see set_transient()
    32773388 * @since 2.9.0
    32783389 * @package WordPress
    32793390 * @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.
    32803395 *
    32813396 * @param string $transient Transient name. Expected to not be SQL-escaped
    32823397 * @param mixed $value Transient value.
     
    32843399 * @return bool False if value was not set and true if value was set.
    32853400 */
    32863401function set_site_transient($transient, $value, $expiration = 0) {
    3287         global $_wp_using_ext_object_cache, $wpdb;
     3402        global $_wp_using_ext_object_cache;
    32883403
     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 );
    32893408        if ( $_wp_using_ext_object_cache ) {
    3290                 return wp_cache_set($transient, $value, 'site-transient', $expiration);
     3409                $result = wp_cache_set($transient, $value, 'site-transient', $expiration);
    32913410        } else {
    32923411                $transient_timeout = '_site_transient_timeout_' . $transient;
    32933412                $transient = '_site_transient_' . $transient;
    32943413                $safe_transient = esc_sql($transient);
    32953414                if ( false === get_site_option( $safe_transient ) ) {
    32963415                        if ( 0 != $expiration )
    3297                                 add_site_option($transient_timeout, time() + $expiration);
    3298                         return add_site_option($transient, $value);
     3416                                add_site_option( $transient_timeout, time() + $expiration );
     3417                        $result = add_site_option($transient, $value);
    32993418                } else {
    33003419                        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 );
    33033422                }
    33043423        }
     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;
    33053429}
    33063430
    33073431/**
     
    35933717function _search_terms_tidy($t) {
    35943718        return trim($t, "\"\'\n\r ");
    35953719}
    3596 ?>
     3720?>
     3721 No newline at end of file