WordPress.org

Make WordPress Core

Ticket #10788: options-transients-apis-2.patch

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

Second pass.

  • 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
     
    302302 * name. You should not try to override special options, but you will not be
    303303 * prevented from doing so.
    304304 *
    305  * There is a second filter called 'option_$option' with the $option being
    306  * replaced with the option name. This gives the value as the only parameter.
    307  *
    308305 * If the option was serialized, when the option was added and, or updated, then
    309306 * it will be unserialized, when it is returned.
    310307 *
    311308 * @since 1.5.0
    312309 * @package WordPress
    313310 * @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.
     311 * @uses apply_filters() Calls 'pre_option_$option' to allow overwriting
     312 *       the option value in a plugin before the option value is retrieved.
     313 * @uses apply_filters() Calls 'option_$option' to allow overwriting the option value
     314 *   in a plugin after the option value is retrieved.
    317315 *
    318  * @param string $setting Name of option to retrieve. Should already be SQL-escaped
     316 * @param string $option Name of option to retrieve. Should already be SQL-escaped
     317 * @param mixed $default Optional value to return if option doesn't exist
    319318 * @return mixed Value set for the option.
    320319 */
    321 function get_option( $setting, $default = false ) {
     320function get_option( $option, $default = false ) {
    322321        global $wpdb;
    323322
    324323        // Allow plugins to short-circuit options.
    325         $pre = apply_filters( 'pre_option_' . $setting, false );
     324        $pre = apply_filters( "pre_option_{$option}", false );
    326325        if ( false !== $pre )
    327326                return $pre;
    328327
    329328        // prevent non-existent options from triggering multiple queries
    330329        $notoptions = wp_cache_get( 'notoptions', 'options' );
    331         if ( isset( $notoptions[$setting] ) )
     330        if ( isset( $notoptions[$option] ) )
    332331                return $default;
    333332
    334333        $alloptions = wp_load_alloptions();
    335334
    336         if ( isset( $alloptions[$setting] ) ) {
    337                 $value = $alloptions[$setting];
     335        if ( isset( $alloptions[$option] ) ) {
     336                $value = $alloptions[$option];
    338337        } else {
    339                 $value = wp_cache_get( $setting, 'options' );
     338                $value = wp_cache_get( $option, 'options' );
    340339
    341340                if ( false === $value ) {
    342341                        if ( defined( 'WP_INSTALLING' ) )
    343342                                $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" );
     343                        // expected_slashed ($option)
     344                        $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$option' LIMIT 1" );
    346345                        if ( defined( 'WP_INSTALLING' ) )
    347346                                $wpdb->suppress_errors($suppress);
    348347
    349                         if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     348                        // Has to be get_row instead of get_var because of funkiness with 0, false, null values
     349                        if ( is_object( $row ) ) {
    350350                                $value = $row->option_value;
    351                                 wp_cache_add( $setting, $value, 'options' );
     351                                wp_cache_add( $option, $value, 'options' );
    352352                        } else { // option does not exist, so we must cache its non-existence
    353                                 $notoptions[$setting] = true;
     353                                $notoptions[$option] = true;
    354354                                wp_cache_set( 'notoptions', $notoptions, 'options' );
    355355                                return $default;
    356356                        }
     
    358358        }
    359359
    360360        // If home is not set use siteurl.
    361         if ( 'home' == $setting && '' == $value )
     361        if ( 'home' == $option && '' == $value )
    362362                return get_option( 'siteurl' );
    363363
    364         if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) )
     364        if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
    365365                $value = untrailingslashit( $value );
    366366
    367         return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) );
     367        return apply_filters( "option_{$option}", maybe_unserialize( $value ) );
    368368}
    369369
    370370/**
     
    404404 *
    405405 * This is different from wp_load_alloptions() in that this function does not
    406406 * cache its results and will retrieve all options from the database every time
    407  *
    408407 * it is called.
    409408 *
    410409 * @since 1.0.0
     
    423422        $wpdb->show_errors($show);
    424423
    425424        foreach ( (array) $options as $option ) {
    426                 // "When trying to design a foolproof system,
    427                 //  never underestimate the ingenuity of the fools :)" -- Dougal
     425                // A common mistake people make when trying to design something completely foolproof
     426                // is to underestimate the ingenuity of complete fools. -- Douglas Adams
    428427                if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
    429428                        $option->option_value = untrailingslashit( $option->option_value );
    430429                $value = maybe_unserialize( $option->option_value );
     
    474473 * value, but you will not be able to set whether it is autoloaded. If you want
    475474 * to set whether an option autoloaded, then you need to use the add_option().
    476475 *
    477  * 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.
     476 * Before the option is updated, then the filter named 'pre_update_option_$option'
     477 * with the $option as the $option parameter value, will be called. The hook should
     478 * accept two parameters, the first is the new value and the second is the old value.
     479 * Whatever is returned will be used as the new value.
    482480 *
    483  * After the value has been updated the action named 'update_option_$option_name'
    484  * will be called.  This action receives two parameters the first being the old
    485  * value and the second the new value.
     481 * After the value has been updated the actions named 'update_option_$option' and
     482 * 'updated_option' will be called. The actions receive the old and new values.
    486483 *
    487484 * @since 1.0.0
    488485 * @package WordPress
    489486 * @subpackage Option
     487 * @uses apply_filters() Calls 'pre_update_option_$option' to allow overwriting
     488 *   the option value in a plugin.
     489 * @uses do_action() Calls 'update_option' before updating the option.
     490 * @uses do_action() Calls 'update_option_$option' and 'updated_option' hooks on success.
    490491 *
    491  * @param string $option_name Option name. Expected to not be SQL-escaped
    492  * @param mixed $newvalue Option value.
     492 * @param string $option Option name. Expected to not be SQL-escaped
     493 * @param mixed $value Option value.
    493494 * @return bool False if value was not updated and true if value was updated.
    494495 */
    495 function update_option( $option_name, $newvalue ) {
     496function update_option( $option, $value ) {
    496497        global $wpdb;
    497498
    498         wp_protect_special_option( $option_name );
     499        wp_protect_special_option( $option );
    499500
    500         $safe_option_name = esc_sql( $option_name );
    501         $newvalue = sanitize_option( $option_name, $newvalue );
     501        $safe_option = esc_sql( $option );
     502        $new_value   = sanitize_option( $option, $value );
     503        $old_value   = get_option( $safe_option );
     504        $new_value   = apply_filters( "pre_update_option_{$option}", $new_value, $old_value );
    502505
    503         $oldvalue = get_option( $safe_option_name );
    504 
    505         $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue );
    506 
    507506        // If the new and old values are the same, no need to update.
    508         if ( $newvalue === $oldvalue )
     507        if ( $new_value === $old_value )
    509508                return false;
    510509
    511         if ( false === $oldvalue ) {
    512                 add_option( $option_name, $newvalue );
    513                 return true;
    514         }
     510        if ( false === $old_value )
     511                return add_option( $option, $new_value );
    515512
    516513        $notoptions = wp_cache_get( 'notoptions', 'options' );
    517         if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) {
    518                 unset( $notoptions[$option_name] );
     514        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
     515                unset( $notoptions[$option] );
    519516                wp_cache_set( 'notoptions', $notoptions, 'options' );
    520517        }
    521518
    522         $_newvalue = $newvalue;
    523         $newvalue = maybe_serialize( $newvalue );
     519        $_new_value = $new_value;
     520        $new_value  = maybe_serialize( $new_value );
    524521
    525         do_action( 'update_option', $option_name, $oldvalue, $newvalue );
     522        do_action( 'update_option', $option, $old_value, $new_value );
    526523        $alloptions = wp_load_alloptions();
    527         if ( isset( $alloptions[$option_name] ) ) {
    528                 $alloptions[$option_name] = $newvalue;
     524        if ( isset( $alloptions[$option] ) ) {
     525                $alloptions[$option] = $new_value;
    529526                wp_cache_set( 'alloptions', $alloptions, 'options' );
    530527        } else {
    531                 wp_cache_set( $option_name, $newvalue, 'options' );
     528                wp_cache_set( $option, $new_value, 'options' );
    532529        }
    533530
    534         $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
     531        $wpdb->update($wpdb->options, array('option_value' => $new_value), array('option_name' => $option) );
    535532
    536533        if ( $wpdb->rows_affected == 1 ) {
    537                 do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
    538                 do_action( 'updated_option', $option_name, $oldvalue, $_newvalue );
     534                do_action( "update_option_{$option}", $old_value, $_new_value );
     535                do_action( 'updated_option', $option, $old_value, $_new_value );
    539536                return true;
    540537        }
    541538        return false;
     
    544541/**
    545542 * Add a new option.
    546543 *
    547  * You do not need to serialize values, if the value needs to be serialize, then
     544 * You do not need to serialize values. If the value needs to be serialized, then
    548545 * it will be serialized before it is inserted into the database. Remember,
    549546 * resources can not be serialized or added as an option.
    550547 *
     
    554551 * options, the same as the ones which are protected and to not add options
    555552 * that were already added.
    556553 *
    557  * The filter named 'add_option_$optionname', with the $optionname being
    558  * replaced with the option's name, will be called. The hook should accept two
    559  * parameters, the first is the option name, and the second is the value.
    560  *
    561554 * @package WordPress
    562555 * @subpackage Option
    563556 * @since 1.0.0
    564557 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
     558 * @uses apply_filters() Calls 'pre_add_option_$option' to allow overwriting
     559 *   the option value in a plugin.
     560 * @uses do_action() Calls 'add_option' before adding the option.
     561 * @uses do_action() Calls 'added_option_$option' and 'added_option' hooks on success.
    565562 *
    566  * @param string $name Option name to add. Expects to NOT be SQL escaped.
     563 * @param string $option Name of option to add. Expects to not be SQL escaped.
    567564 * @param mixed $value Optional. Option value, can be anything.
    568565 * @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.
     566 * @param bool $autoload Optional. Whether to load the option when WordPress starts up. Default is enabled.
     567 * @return bool False if option was not added and true if option was added.
    571568 */
    572 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) {
     569function add_option( $option, $value = '', $deprecated = '', $autoload = true ) {
    573570        global $wpdb;
    574571
    575         wp_protect_special_option( $name );
    576         $safe_name = esc_sql( $name );
    577         $value = sanitize_option( $name, $value );
     572        wp_protect_special_option( $option );
     573        $safe_name = esc_sql( $option );
    578574
     575        $value = sanitize_option( $option, $value );
     576        $value = apply_filters( "pre_add_option_{$option}", $value );
     577
    579578        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    580579        $notoptions = wp_cache_get( 'notoptions', 'options' );
    581         if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) )
     580        if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
    582581                if ( false !== get_option( $safe_name ) )
    583                         return;
     582                        return false;
    584583
    585584        $value = maybe_serialize( $value );
    586         $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
    587         do_action( 'add_option', $name, $value );
    588         if ( 'yes' == $autoload ) {
     585        $autoload = ( $autoload && 'no' != $autoload ) ? true : false;
     586        do_action( 'add_option', $option, $value );
     587        if ( $autoload ) {
    589588                $alloptions = wp_load_alloptions();
    590                 $alloptions[$name] = $value;
     589                $alloptions[$option] = $value;
    591590                wp_cache_set( 'alloptions', $alloptions, 'options' );
    592591        } else {
    593                 wp_cache_set( $name, $value, 'options' );
     592                wp_cache_set( $option, $value, 'options' );
    594593        }
    595594
    596595        // This option exists now
    597596        $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] );
     597        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
     598                unset( $notoptions[$option] );
    600599                wp_cache_set( 'notoptions', $notoptions, 'options' );
    601600        }
    602601
    603         $wpdb->insert($wpdb->options, array('option_name' => $name, 'option_value' => $value, 'autoload' => $autoload) );
     602        $wpdb->insert($wpdb->options, array('option_name' => $option, 'option_value' => $value, 'autoload' => ( $autoload ) ? 'yes' : 'no' ) );
    604603
    605         do_action( "add_option_{$name}", $name, $value );
    606         do_action( 'added_option', $name, $value );
    607        
    608         return;
     604        do_action( "add_option_{$option}", $option, $value );
     605        do_action( 'added_option', $option, $value );
     606
     607        return true;
    609608}
    610609
    611610/**
    612  * Removes option by name and prevents removal of protected WordPress options.
     611 * Removes option by name. Prevents removal of protected WordPress options.
    613612 *
    614613 * @package WordPress
    615614 * @subpackage Option
    616615 * @since 1.2.0
     616 * @uses do_action() Calls 'delete_option' before deleting the option.
     617 * @uses do_action() Calls 'delete_option_$option' and 'deleted_option'
     618 *   hooks on success.
    617619 *
    618  * @param string $name Option name to remove.
    619  * @return bool True, if succeed. False, if failure.
     620 * @param string $option Name of option to remove. Expected to be SQL-escaped.
     621 * @return bool True, on success. False, on failure.
    620622 */
    621 function delete_option( $name ) {
     623function delete_option( $option ) {
    622624        global $wpdb;
    623625
    624         wp_protect_special_option( $name );
     626        wp_protect_special_option( $option );
    625627
    626628        // Get the ID, if no ID then return
    627629        // expected_slashed ($name)
    628         $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" );
     630        $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$option'" );
    629631        if ( is_null($option) )
    630632                return false;
    631         do_action( 'delete_option', $name );
     633        do_action( 'delete_option', $option );
    632634        // expected_slashed ($name)
    633         $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
     635        $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$option'" );
    634636        if ( 'yes' == $option->autoload ) {
    635637                $alloptions = wp_load_alloptions();
    636                 if ( isset( $alloptions[$name] ) ) {
    637                         unset( $alloptions[$name] );
     638                if ( isset( $alloptions[$option] ) ) {
     639                        unset( $alloptions[$option] );
    638640                        wp_cache_set( 'alloptions', $alloptions, 'options' );
    639641                }
    640642        } else {
    641                 wp_cache_delete( $name, 'options' );
     643                wp_cache_delete( $option, 'options' );
    642644        }
    643         do_action( 'deleted_option', $name );
     645        do_action( "delete_option_{$option}", $option );
     646        do_action( 'deleted_option', $option );
    644647        return true;
    645648}
    646649
     
    650653 * @since 2.8.0
    651654 * @package WordPress
    652655 * @subpackage Transient
     656 * @uses do_action() Calls 'delete_transient' before deleting the transient.
     657 * @uses do_action() Calls 'delete_transient_$transient' and 'deleted_transient'
     658 *   hooks on success.
    653659 *
    654660 * @param string $transient Transient name. Expected to not be SQL-escaped
    655661 * @return bool true if successful, false otherwise
    656662 */
    657663function delete_transient($transient) {
    658         global $_wp_using_ext_object_cache, $wpdb;
     664        global $_wp_using_ext_object_cache;
    659665
     666        $_transient = $transient;
     667        do_action( 'delete_transient', $transient );
    660668        if ( $_wp_using_ext_object_cache ) {
    661                 return wp_cache_delete($transient, 'transient');
     669                $result = wp_cache_delete( $transient, 'transient' );
    662670        } else {
    663                 $transient = '_transient_' . esc_sql($transient);
    664                 return delete_option($transient);
     671                $result = delete_option( '_transient_' . esc_sql( $transient ) );
    665672        }
     673
     674        if ( $result ) {
     675                do_action( "delete_transient_{$transient}", $transient );
     676                do_action( 'deleted_transient', $transient );
     677        }
     678        return $result;
    666679}
    667680
    668681/**
     
    674687 * @since 2.8.0
    675688 * @package WordPress
    676689 * @subpackage Transient
     690 * @uses apply_filters() Calls 'pre_transient_$transient' to allow overwriting
     691 *   the transient value in a plugin before checking the transient.
     692 * @uses apply_filters() Calls 'transient_$transient' to allow overwriting
     693 *   the transient value in a plugin after checking the transient.
    677694 *
    678695 * @param string $transient Transient name. Expected to not be SQL-escaped
    679696 * @return mixed Value of transient
    680697 */
    681698function get_transient($transient) {
    682         global $_wp_using_ext_object_cache, $wpdb;
     699        global $_wp_using_ext_object_cache;
    683700
    684         $pre = apply_filters( 'pre_transient_' . $transient, false );
     701        $pre = apply_filters( "pre_transient_{$transient}", false );
    685702        if ( false !== $pre )
    686703                return $pre;
    687704
    688705        if ( $_wp_using_ext_object_cache ) {
    689706                $value = wp_cache_get($transient, 'transient');
    690707        } else {
    691                 $transient_option = '_transient_' . esc_sql($transient);
     708                $safe_transient = esc_sql( $transient );
     709                $transient_option = '_transient_' . $safe_transient;
    692710                // If option is not in alloptions, it is not autoloaded and thus has a timeout
    693711                $alloptions = wp_load_alloptions();
    694712                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);
     713                        $transient_timeout = '_transient_timeout_' . $safe_transient;
     714                        if ( get_option( $transient_timeout ) < time() ) {
     715                                delete_option( $transient_option  );
     716                                delete_option( $transient_timeout );
    699717                                return false;
    700718                        }
    701719                }
    702720
    703                 $value = get_option($transient_option);
     721                $value = get_option( $transient_option );
    704722        }
    705723
    706         return apply_filters('transient_' . $transient, $value);
     724        return apply_filters( "transient_{$transient}", $value );
    707725}
    708726
    709727/**
     
    715733 * @since 2.8.0
    716734 * @package WordPress
    717735 * @subpackage Transient
     736 * @uses apply_filters() Calls 'pre_set_transient_$transient' to allow overwriting
     737 *              the transient value in a plugin.
     738 * @uses apply_filters() Calls 'pre_set_transient_expiration_$transient' to allow overwriting
     739 *              the transient expiration in a plugin.
     740 * @uses do_action() Calls 'set_transient' before setting the transient.
     741 * @uses do_action() Calls 'set_transient_$transient' and 'setted_transient' hooks on success.
    718742 *
    719743 * @param string $transient Transient name. Expected to not be SQL-escaped
    720744 * @param mixed $value Transient value.
     
    722746 * @return bool False if value was not set and true if value was set.
    723747 */
    724748function set_transient($transient, $value, $expiration = 0) {
    725         global $_wp_using_ext_object_cache, $wpdb;
     749        global $_wp_using_ext_object_cache;
    726750
     751        $value = apply_filters( "pre_set_transient_{$transient}", $value, $expiration );
     752        $expiration = apply_filters( "pre_set_transient_expiration_{$transient}", $expiration, $value );
     753
     754        do_action( 'set_transient', $transient, $value, $expiration );
    727755        if ( $_wp_using_ext_object_cache ) {
    728                 return wp_cache_set($transient, $value, 'transient', $expiration);
     756                $result = wp_cache_set($transient, $value, 'transient', $expiration);
    729757        } else {
    730758                $transient_timeout = '_transient_timeout_' . $transient;
    731759                $transient = '_transient_' . $transient;
     
    734762                        $autoload = 'yes';
    735763                        if ( 0 != $expiration ) {
    736764                                $autoload = 'no';
    737                                 add_option($transient_timeout, time() + $expiration, '', 'no');
     765                                add_option( $transient_timeout, time() + $expiration, '', 'no' );
    738766                        }
    739                         return add_option($transient, $value, '', $autoload);
     767                        $result = add_option( $transient, $value, '', $autoload );
    740768                } else {
    741769                        if ( 0 != $expiration )
    742                                 update_option($transient_timeout, time() + $expiration);
    743                         return update_option($transient, $value);
     770                                update_option( $transient_timeout, time() + $expiration );
     771                        $result = update_option( $transient, $value );
    744772                }
    745773        }
     774        if ( $result ) {
     775                do_action( "set_transient_{$transient}", $transient, $value, $expiration );
     776                do_action( 'setted_transient', $transient, $value, $expiration );
     777        }
     778        return $result;
    746779}
    747780
    748781/**
     
    31763209        return $current_suspend;
    31773210}
    31783211
    3179 function get_site_option( $key, $default = false, $use_cache = true ) {
     3212/**
     3213 * Retrieve site option value based on option name.
     3214 *
     3215 * @see get_option()
     3216 * @package WordPress
     3217 * @subpackage Option
     3218 * @since 2.8.0
     3219 * @uses apply_filters() Calls 'pre_site_option_$option' to allow overwriting
     3220 *       the option value in a plugin before retrieving the value.
     3221 * @uses apply_filters() Calls 'site_option_$option' to allow overwriting
     3222 *       the option value in a plugin after retrieving the value.
     3223 *
     3224 * @param string $option Name of option to retrieve. Should already be SQL-escaped
     3225 * @param mixed $default Optional value to return if option doesn't exist
     3226 * @param use_cache Used only in WordPress MU.
     3227 * @return mixed Value set for the option.
     3228 */
     3229function get_site_option( $option, $default = false, $use_cache = true ) {
    31803230        // Allow plugins to short-circuit site options.
    3181         $pre = apply_filters( 'pre_site_option_' . $key, false );
     3231        $pre = apply_filters( "pre_site_option_{$option}", false );
    31823232        if ( false !== $pre )
    31833233                return $pre;
    31843234
    3185         $value = get_option($key, $default);
     3235        $value = get_option( $option, $default ) ;
    31863236
    3187         return apply_filters( 'site_option_' . $key, $value );
     3237        return apply_filters( "site_option_{$option}", $value );
    31883238}
    31893239
    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 );
     3240/**
     3241 * Add a new site option.
     3242 *
     3243 * @see add_option()
     3244 * @package WordPress
     3245 * @subpackage Option
     3246 * @since 2.8.0
     3247 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton
     3248 * @uses apply_filters() Calls 'pre_add_site_option_$option' to allow overwriting
     3249 *   the option value in a plugin.
     3250 * @uses do_action() Calls 'add_site_option' before adding the option.
     3251 * @uses do_action() Calls 'added_site_option_$option' and 'added_site_option' hooks on success.
     3252 *
     3253 * @param string $option Name of option to add. Expects to not be SQL escaped.
     3254 * @param mixed $value Optional. Option value, can be anything.
     3255 * @return bool False if option was not added and true if option was added.
     3256 */
     3257function add_site_option( $option, $value ) {
     3258        $value = apply_filters( "pre_add_site_option_{$option}", $value );
     3259        do_action( 'add_site_option', $option, $value );
     3260        $result = add_option( $option, $value );
     3261        if ( $result ) {
     3262                do_action( "add_site_option_{$option}", $option, $value );
     3263                do_action( 'added_site_option', $option, $value );
     3264        }
    31953265        return $result;
    31963266}
    31973267
    3198 function delete_site_option( $key ) {
    3199         $result = delete_option($key);
    3200         do_action( "delete_site_option_{$key}", $key );
     3268/**
     3269 * Removes site option by name.
     3270 *
     3271 * @see delete_option()
     3272 * @package WordPress
     3273 * @subpackage Option
     3274 * @since 2.8.0
     3275 * @uses do_action() Calls 'delete_site_option' before deleting the option.
     3276 * @uses do_action() Calls 'delete_site_option_$option' and 'deleted_site_option'
     3277 *   hooks on success.
     3278 *
     3279 * @param string $option Name of option to remove. Expected to be SQL-escaped.
     3280 * @return bool True, if succeed. False, if failure.
     3281 */
     3282function delete_site_option( $option ) {
     3283        do_action( 'delete_site_option', $option );
     3284        $result = delete_option( $option );
     3285        if ( $result ) {
     3286                do_action( "delete_site_option_{$option}", $option );
     3287                do_action( 'deleted_site_option', $option );
     3288        }
    32013289        return $result;
    32023290}
    32033291
    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 );
     3292/**
     3293 * Update the value of a site option that was already added.
     3294 *
     3295 * @see update_option()
     3296 * @since 2.8.0
     3297 * @package WordPress
     3298 * @subpackage Option
     3299 * @uses apply_filters() Calls 'pre_update_site_option_$option' to allow overwriting
     3300 *   the option value in a plugin.
     3301 * @uses do_action() Calls 'update_site_option' before updating the option.
     3302 * @uses do_action() Calls 'update_site_option_$option' and 'updated_site_option' hooks on success.
     3303 *
     3304 * @param string $option Option name. Expected to not be SQL-escaped
     3305 * @param mixed $value Option value.
     3306 * @return bool False if value was not updated and true if value was updated.
     3307 */
     3308function update_site_option( $option, $value ) {
     3309        $old_value = get_site_option( $option );
     3310        $new_value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value );
     3311
     3312        if ( $new_value === $old_value )
     3313                return false;
     3314
     3315        if ( false === $old_value )
     3316                return add_site_option( $option, $new_value );
     3317
     3318        do_action( 'update_site_option', $option, $old_value, $new_value );
     3319        $result = update_option( $option, $new_value );
     3320        if ( $result ) {
     3321                do_action( "update_site_option_{$option}", $option, $old_value, $new_value );
     3322                do_action( 'updated_site_option', $option, $old_value, $new_value );
     3323        }
    32103324        return $result;
    32113325}
    32123326
    32133327/**
    32143328 * Delete a site transient
    32153329 *
    3216  * @since 2.890
     3330 * @see delete_transient()
     3331 * @since 2.9.0
    32173332 * @package WordPress
    32183333 * @subpackage Transient
     3334 * @uses do_action() Calls 'delete_site_transient' before deleting the transient.
     3335 * @uses do_action() Calls 'delete_site_transient_$transient' and 'deleted_site_transient'
     3336 *   hooks on success.
    32193337 *
    32203338 * @param string $transient Transient name. Expected to not be SQL-escaped
    32213339 * @return bool true if successful, false otherwise
    32223340 */
    32233341function delete_site_transient($transient) {
    3224         global $_wp_using_ext_object_cache, $wpdb;
     3342        global $_wp_using_ext_object_cache;
    32253343
     3344        do_action( 'delete_site_transient', $transient );
    32263345        if ( $_wp_using_ext_object_cache ) {
    3227                 return wp_cache_delete($transient, 'site-transient');
     3346                $result = wp_cache_delete( $transient, 'site-transient' );
    32283347        } else {
    3229                 $transient = '_site_transient_' . esc_sql($transient);
    3230                 return delete_site_option($transient);
     3348                $result = delete_site_option( '_site_transient_' . esc_sql( $transient ) );
    32313349        }
     3350
     3351        if ( $result ) {
     3352                do_action( "delete_site_transient_{$transient}", $transient );
     3353                do_action( 'deleted_site_transient', $transient );
     3354        }
     3355        return $result;
    32323356}
    32333357
    32343358/**
     
    32363360 *
    32373361 * If the transient does not exist or does not have a value, then the return value
    32383362 * will be false.
    3239  *
     3363 *
     3364 * @see get_transient()
    32403365 * @since 2.9.0
    32413366 * @package WordPress
    32423367 * @subpackage Transient
     3368 * @uses apply_filters() Calls 'pre_site_transient_$transient' to allow overwriting
     3369 *   the transient value in a plugin before checking the transient.
     3370 * @uses apply_filters() Calls 'site_transient_$transient' to allow overwriting
     3371 *   the transient value in a plugin after checking the transient.
    32433372 *
    32443373 * @param string $transient Transient name. Expected to not be SQL-escaped
    32453374 * @return mixed Value of transient
    32463375 */
    32473376function get_site_transient($transient) {
    3248         global $_wp_using_ext_object_cache, $wpdb;
     3377        global $_wp_using_ext_object_cache;
    32493378
    3250         $pre = apply_filters( 'pre_site_transient_' . $transient, false );
     3379        $pre = apply_filters( "pre_site_transient_{$transient}", false );
    32513380        if ( false !== $pre )
    32523381                return $pre;
    32533382
    32543383        if ( $_wp_using_ext_object_cache ) {
    3255                 $value = wp_cache_get($transient, 'site-transient');
     3384                $value = wp_cache_get( $transient, 'site-transient' );
    32563385        } 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);
     3386                $safe_transient = esc_sql( $transient );
     3387                $transient_option = '_site_transient_' . $safe_transient;
     3388                $transient_timeout = '_site_transient_timeout_' . $safe_transient;
     3389                if ( get_site_option( $transient_timeout ) < time() ) {
     3390                        delete_site_option( $transient_option  );
     3391                        delete_site_option( $transient_timeout );
    32623392                        return false;
    32633393                }
    32643394
    3265                 $value = get_site_option($transient_option);
     3395                $value = get_site_option( $transient_option );
    32663396        }
    32673397
    3268         return apply_filters('site_transient_' . $transient, $value);
     3398        return apply_filters( "site_transient_{$transient}", $value );
    32693399}
    32703400
    32713401/**
     
    32743404 * You do not need to serialize values, if the value needs to be serialize, then
    32753405 * it will be serialized before it is set.
    32763406 *
     3407 * @see set_transient()
    32773408 * @since 2.9.0
    32783409 * @package WordPress
    32793410 * @subpackage Transient
     3411 * @uses apply_filters() Calls 'pre_set_site_transient_$transient' to allow overwriting
     3412 *              the transient value in a plugin.
     3413 * @uses apply_filters() Calls 'pre_set_site_transient_expiration_$transient' to allow overwriting
     3414 *              the transient expiration in a plugin.
     3415 * @uses do_action() Calls 'set_site_transient' before setting the transient.
     3416 * @uses do_action() Calls 'set_site_transient_$transient' and 'setted_site_transient' hooks on success.
    32803417 *
    32813418 * @param string $transient Transient name. Expected to not be SQL-escaped
    32823419 * @param mixed $value Transient value.
     
    32843421 * @return bool False if value was not set and true if value was set.
    32853422 */
    32863423function set_site_transient($transient, $value, $expiration = 0) {
    3287         global $_wp_using_ext_object_cache, $wpdb;
     3424        global $_wp_using_ext_object_cache;
    32883425
     3426        $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $expiration );
     3427        $expiration = apply_filters( "pre_set_site_transient_expiration_{$transient}", $expiration, $value );
     3428
     3429        do_action( 'set_site_transient', $transient, $value, $expiration );
    32893430        if ( $_wp_using_ext_object_cache ) {
    3290                 return wp_cache_set($transient, $value, 'site-transient', $expiration);
     3431                $result = wp_cache_set($transient, $value, 'site-transient', $expiration);
    32913432        } else {
    32923433                $transient_timeout = '_site_transient_timeout_' . $transient;
    32933434                $transient = '_site_transient_' . $transient;
    32943435                $safe_transient = esc_sql($transient);
    32953436                if ( false === get_site_option( $safe_transient ) ) {
    32963437                        if ( 0 != $expiration )
    3297                                 add_site_option($transient_timeout, time() + $expiration);
    3298                         return add_site_option($transient, $value);
     3438                                add_site_option( $transient_timeout, time() + $expiration );
     3439                        $result = add_site_option($transient, $value);
    32993440                } else {
    33003441                        if ( 0 != $expiration )
    3301                                 update_site_option($transient_timeout, time() + $expiration);
    3302                         return update_site_option($transient, $value);
     3442                                update_site_option( $transient_timeout, time() + $expiration );
     3443                        $result = update_site_option( $transient, $value );
    33033444                }
    33043445        }
     3446        if ( $result ) {
     3447                do_action( "set_site_transient_{$transient}", $transient, $value, $expiration );
     3448                do_action( 'setted_site_transient', $transient, $value, $expiration );
     3449        }
     3450        return $result;
    33053451}
    33063452
    33073453/**
     
    35933739function _search_terms_tidy($t) {
    35943740        return trim($t, "\"\'\n\r ");
    35953741}
    3596 ?>
     3742?>
     3743 No newline at end of file