WordPress.org

Make WordPress Core

Changeset 13139


Ignore:
Timestamp:
02/14/10 06:17:42 (6 years ago)
Author:
nacin
Message:

Whitespace, phpdoc, standard variable names, better return values for options and transients APIs. See #10788

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r13102 r13139  
    312312 * @package WordPress 
    313313 * @subpackage Option 
    314  * @uses apply_filters() Calls 'pre_option_$optionname' false to allow 
     314 * @uses apply_filters() Calls 'pre_option_$option' false to allow 
    315315 *      overwriting the option value in a plugin. 
    316  * @uses apply_filters() Calls 'option_$optionname' with the option name value. 
    317  * 
    318  * @param string $setting Name of option to retrieve. Should already be SQL-escaped 
     316 * @uses apply_filters() Calls 'option_$option' with the option value. 
     317 * 
     318 * @param string $option Name of option to retrieve. Should already be SQL-escaped 
    319319 * @return mixed Value set for the option. 
    320320 */ 
    321 function get_option( $setting, $default = false ) { 
     321function get_option( $option, $default = false ) { 
    322322    global $wpdb; 
    323323 
    324324    // Allow plugins to short-circuit options. 
    325     $pre = apply_filters( 'pre_option_' . $setting, false ); 
     325    $pre = apply_filters( 'pre_option_' . $option, false ); 
    326326    if ( false !== $pre ) 
    327327        return $pre; 
     
    332332    } else { 
    333333        $notoptions = wp_cache_get( 'notoptions', 'options' ); 
    334         if ( isset( $notoptions[$setting] ) ) 
     334        if ( isset( $notoptions[$option] ) ) 
    335335            return $default; 
    336336    } 
     
    340340    } 
    341341 
    342     if ( isset( $alloptions[$setting] ) ) { 
    343         $value = $alloptions[$setting]; 
     342    if ( isset( $alloptions[$option] ) ) { 
     343        $value = $alloptions[$option]; 
    344344    } else { 
    345         $value = wp_cache_get( $setting, 'options' ); 
     345        $value = wp_cache_get( $option, 'options' ); 
    346346 
    347347        if ( false === $value ) { 
    348348            if ( defined( 'WP_INSTALLING' ) ) 
    349349                $suppress = $wpdb->suppress_errors(); 
    350             // expected_slashed ($setting) 
    351             $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1" ); 
     350            // expected_slashed ($option) 
     351            $row = $wpdb->get_row( "SELECT option_value FROM $wpdb->options WHERE option_name = '$option' LIMIT 1" ); 
    352352            if ( defined( 'WP_INSTALLING' ) ) 
    353                 $wpdb->suppress_errors($suppress); 
     353                $wpdb->suppress_errors( $suppress ); 
    354354 
    355355            if ( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 
    356356                $value = $row->option_value; 
    357                 wp_cache_add( $setting, $value, 'options' ); 
     357                wp_cache_add( $option, $value, 'options' ); 
    358358            } else { // option does not exist, so we must cache its non-existence 
    359                 $notoptions[$setting] = true; 
     359                $notoptions[$option] = true; 
    360360                wp_cache_set( 'notoptions', $notoptions, 'options' ); 
    361361                return $default; 
     
    365365 
    366366    // If home is not set use siteurl. 
    367     if ( 'home' == $setting && '' == $value ) 
     367    if ( 'home' == $option && '' == $value ) 
    368368        return get_option( 'siteurl' ); 
    369369 
    370     if ( in_array( $setting, array('siteurl', 'home', 'category_base', 'tag_base') ) ) 
     370    if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) ) 
    371371        $value = untrailingslashit( $value ); 
    372372 
    373     return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) ); 
     373    return apply_filters( 'option_' . $option, maybe_unserialize( $value ) ); 
    374374} 
    375375 
     
    482482 * 
    483483 * Before the option is updated, then the filter named 
    484  * 'pre_update_option_$option_name', with the $option_name as the $option_name 
     484 * 'pre_update_option_$option', with the $option as the $option 
    485485 * parameter value, will be called. The hook should accept two parameters, the 
    486486 * first is the new value and the second is the old value.  Whatever is 
    487487 * returned will be used as the new value. 
    488488 * 
    489  * After the value has been updated the action named 'update_option_$option_name' 
     489 * After the value has been updated the action named 'update_option_$option' 
    490490 * will be called.  This action receives two parameters the first being the old 
    491491 * value and the second the new value. 
     
    495495 * @subpackage Option 
    496496 * 
    497  * @param string $option_name Option name. Expected to not be SQL-escaped 
     497 * @param string $option Option name. Expected to not be SQL-escaped 
    498498 * @param mixed $newvalue Option value. 
    499499 * @return bool False if value was not updated and true if value was updated. 
    500500 */ 
    501 function update_option( $option_name, $newvalue ) { 
     501function update_option( $option, $newvalue ) { 
    502502    global $wpdb; 
    503503 
    504     wp_protect_special_option( $option_name ); 
    505  
    506     $safe_option_name = esc_sql( $option_name ); 
    507     $newvalue = sanitize_option( $option_name, $newvalue ); 
     504    wp_protect_special_option( $option ); 
     505 
     506    $safe_option_name = esc_sql( $option ); 
     507    $newvalue = sanitize_option( $option, $newvalue ); 
    508508 
    509509    $oldvalue = get_option( $safe_option_name ); 
    510510 
    511     $newvalue = apply_filters( 'pre_update_option_' . $option_name, $newvalue, $oldvalue ); 
     511    $newvalue = apply_filters( 'pre_update_option_' . $option, $newvalue, $oldvalue ); 
    512512 
    513513    // If the new and old values are the same, no need to update. 
     
    515515        return false; 
    516516 
    517     if ( false === $oldvalue ) { 
    518         add_option( $option_name, $newvalue ); 
    519         return true; 
    520     } 
     517    if ( false === $oldvalue ) 
     518        return add_option( $option, $newvalue ); 
    521519 
    522520    $notoptions = wp_cache_get( 'notoptions', 'options' ); 
    523     if ( is_array( $notoptions ) && isset( $notoptions[$option_name] ) ) { 
    524         unset( $notoptions[$option_name] ); 
     521    if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 
     522        unset( $notoptions[$option] ); 
    525523        wp_cache_set( 'notoptions', $notoptions, 'options' ); 
    526524    } 
     
    529527    $newvalue = maybe_serialize( $newvalue ); 
    530528 
    531     do_action( 'update_option', $option_name, $oldvalue, $newvalue ); 
     529    do_action( 'update_option', $option, $oldvalue, $newvalue ); 
    532530    if ( ! defined( 'WP_INSTALLING' ) ) { 
    533531        $alloptions = wp_load_alloptions(); 
    534         if ( isset( $alloptions[$option_name] ) ) { 
    535             $alloptions[$option_name] = $newvalue; 
     532        if ( isset( $alloptions[$option] ) ) { 
     533            $alloptions[$option] = $newvalue; 
    536534            wp_cache_set( 'alloptions', $alloptions, 'options' ); 
    537535        } else { 
    538             wp_cache_set( $option_name, $newvalue, 'options' ); 
     536            wp_cache_set( $option, $newvalue, 'options' ); 
    539537        } 
    540538    } 
    541539 
    542     $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) ); 
    543  
    544     if ( $wpdb->rows_affected == 1 ) { 
    545         do_action( "update_option_{$option_name}", $oldvalue, $_newvalue ); 
    546         do_action( 'updated_option', $option_name, $oldvalue, $_newvalue ); 
     540    $result = $wpdb->update( $wpdb->options, array( 'option_value' => $newvalue ), array( 'option_name' => $option ) ); 
     541 
     542    if ( $result ) { 
     543        do_action( "update_option_{$option}", $oldvalue, $_newvalue ); 
     544        do_action( 'updated_option', $option, $oldvalue, $_newvalue ); 
    547545        return true; 
    548546    } 
     
    563561 * that were already added. 
    564562 * 
    565  * The filter named 'add_option_$optionname', with the $optionname being 
     563 * The filter named 'add_option_$option', with the $optionname being 
    566564 * replaced with the option's name, will be called. The hook should accept two 
    567565 * parameters, the first is the option name, and the second is the value. 
     
    572570 * @link http://alex.vort-x.net/blog/ Thanks Alex Stapleton 
    573571 * 
    574  * @param string $name Option name to add. Expects to NOT be SQL escaped. 
     572 * @param string $option Name of option to add. Expects to NOT be SQL escaped. 
    575573 * @param mixed $value Optional. Option value, can be anything. 
    576574 * @param mixed $deprecated Optional. Description. Not used anymore. 
     
    578576 * @return null returns when finished. 
    579577 */ 
    580 function add_option( $name, $value = '', $deprecated = '', $autoload = 'yes' ) { 
     578function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { 
    581579    if ( !empty( $deprecated ) ) 
    582580        _deprecated_argument( __FUNCTION__, '2.3' ); 
     
    584582    global $wpdb; 
    585583 
    586     wp_protect_special_option( $name ); 
    587     $safe_name = esc_sql( $name ); 
    588     $value = sanitize_option( $name, $value ); 
     584    wp_protect_special_option( $option ); 
     585    $safe_name = esc_sql( $option ); 
     586    $value = sanitize_option( $option, $value ); 
    589587 
    590588    // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query 
    591589    $notoptions = wp_cache_get( 'notoptions', 'options' ); 
    592     if ( !is_array( $notoptions ) || !isset( $notoptions[$name] ) ) 
     590    if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) ) 
    593591        if ( false !== get_option( $safe_name ) ) 
    594592            return; 
     
    596594    $value = maybe_serialize( $value ); 
    597595    $autoload = ( 'no' === $autoload ) ? 'no' : 'yes'; 
    598     do_action( 'add_option', $name, $value ); 
     596    do_action( 'add_option', $option, $value ); 
    599597    if ( ! defined( 'WP_INSTALLING' ) ) { 
    600598        if ( 'yes' == $autoload ) { 
    601599            $alloptions = wp_load_alloptions(); 
    602             $alloptions[$name] = $value; 
     600            $alloptions[$option] = $value; 
    603601            wp_cache_set( 'alloptions', $alloptions, 'options' ); 
    604602        } else { 
    605             wp_cache_set( $name, $value, 'options' ); 
     603            wp_cache_set( $option, $value, 'options' ); 
    606604        } 
    607605    } 
     
    609607    // This option exists now 
    610608    $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh 
    611     if ( is_array( $notoptions ) && isset( $notoptions[$name] ) ) { 
    612         unset( $notoptions[$name] ); 
     609    if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { 
     610        unset( $notoptions[$option] ); 
    613611        wp_cache_set( 'notoptions', $notoptions, 'options' ); 
    614612    } 
    615613 
    616     $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $name, $value, $autoload ) ); 
    617  
    618     do_action( "add_option_{$name}", $name, $value ); 
    619     do_action( 'added_option', $name, $value ); 
    620  
    621     return; 
    622 } 
    623  
    624 /** 
    625  * Removes option by name and prevents removal of protected WordPress options. 
     614    $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload ) ); 
     615 
     616    do_action( "add_option_{$option}", $option, $value ); 
     617    do_action( 'added_option', $option, $value ); 
     618 
     619    return $result; 
     620} 
     621 
     622/** 
     623 * Removes option by name. Prevents removal of protected WordPress options. 
    626624 * 
    627625 * @package WordPress 
     
    629627 * @since 1.2.0 
    630628 * 
    631  * @param string $name Option name to remove. 
     629 * @param string $option Name of option to remove. 
    632630 * @return bool True, if succeed. False, if failure. 
    633631 */ 
    634 function delete_option( $name ) { 
     632function delete_option( $option ) { 
    635633    global $wpdb; 
    636634 
    637     wp_protect_special_option( $name ); 
     635    wp_protect_special_option( $option ); 
    638636 
    639637    // Get the ID, if no ID then return 
    640     // expected_slashed ($name) 
    641     $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" ); 
    642     if ( is_null($option) ) 
     638    // expected_slashed ($option) 
     639    $row = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$option'" ); 
     640    if ( is_null( $row ) ) 
    643641        return false; 
    644     do_action( 'delete_option', $name ); 
    645     // expected_slashed ($name) 
    646     $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" ); 
     642    do_action( 'delete_option', $option ); 
     643    // expected_slashed ($option) 
     644    $result = $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$option'" ); 
    647645    if ( ! defined( 'WP_INSTALLING' ) ) { 
    648         if ( 'yes' == $option->autoload ) { 
     646        if ( 'yes' == $row->autoload ) { 
    649647            $alloptions = wp_load_alloptions(); 
    650             if ( isset( $alloptions[$name] ) ) { 
    651                 unset( $alloptions[$name] ); 
     648            if ( isset( $alloptions[$option] ) ) { 
     649                unset( $alloptions[$option] ); 
    652650                wp_cache_set( 'alloptions', $alloptions, 'options' ); 
    653651            } 
    654652        } else { 
    655             wp_cache_delete( $name, 'options' ); 
     653            wp_cache_delete( $option, 'options' ); 
    656654        } 
    657655    } 
    658     do_action( 'deleted_option', $name ); 
     656    do_action( 'deleted_option', $option ); 
    659657    return true; 
    660658} 
     
    670668 * @return bool true if successful, false otherwise 
    671669 */ 
    672 function delete_transient($transient) { 
    673     global $_wp_using_ext_object_cache, $wpdb; 
     670function delete_transient( $transient ) { 
     671    global $_wp_using_ext_object_cache; 
    674672 
    675673    do_action( 'delete_transient_' . $transient ); 
    676674 
    677675    if ( $_wp_using_ext_object_cache ) { 
    678         return wp_cache_delete($transient, 'transient'); 
     676        return wp_cache_delete( $transient, 'transient' ); 
    679677    } else { 
    680         $transient = '_transient_' . esc_sql($transient); 
    681         return delete_option($transient); 
     678        $transient = '_transient_' . esc_sql( $transient ); 
     679        return delete_option( $transient ); 
    682680    } 
    683681} 
     
    696694 * @return mixed Value of transient 
    697695 */ 
    698 function get_transient($transient) { 
    699     global $_wp_using_ext_object_cache, $wpdb; 
     696function get_transient( $transient ) { 
     697    global $_wp_using_ext_object_cache; 
    700698 
    701699    $pre = apply_filters( 'pre_transient_' . $transient, false ); 
     
    704702 
    705703    if ( $_wp_using_ext_object_cache ) { 
    706         $value = wp_cache_get($transient, 'transient'); 
     704        $value = wp_cache_get( $transient, 'transient' ); 
    707705    } else { 
    708         $transient_option = '_transient_' . esc_sql($transient); 
     706        $safe_transient   = esc_sql( $transient ); 
     707        $transient_option = '_transient_' . $safe_transient; 
    709708        if ( ! defined( 'WP_INSTALLING' ) ) { 
    710709            // If option is not in alloptions, it is not autoloaded and thus has a timeout 
    711710            $alloptions = wp_load_alloptions(); 
    712711            if ( !isset( $alloptions[$transient_option] ) ) { 
    713                 $transient_timeout = '_transient_timeout_' . esc_sql($transient); 
    714                 if ( get_option($transient_timeout) < time() ) { 
    715                     delete_option($transient_option); 
    716                     delete_option($transient_timeout); 
     712                $transient_timeout = '_transient_timeout_' . $safe_transient; 
     713                if ( get_option( $transient_timeout ) < time() ) { 
     714                    delete_option( $transient_option  ); 
     715                    delete_option( $transient_timeout ); 
    717716                    return false; 
    718717                } 
     
    720719        } 
    721720 
    722         $value = get_option($transient_option); 
    723     } 
    724  
    725     return apply_filters('transient_' . $transient, $value); 
     721        $value = get_option( $transient_option ); 
     722    } 
     723 
     724    return apply_filters( 'transient_' . $transient, $value ); 
    726725} 
    727726 
     
    729728 * Set/update the value of a transient 
    730729 * 
    731  * You do not need to serialize values, if the value needs to be serialize, then 
     730 * You do not need to serialize values. If the value needs to be serialized, then 
    732731 * it will be serialized before it is set. 
    733732 * 
     
    741740 * @return bool False if value was not set and true if value was set. 
    742741 */ 
    743 function set_transient($transient, $value, $expiration = 0) { 
    744     global $_wp_using_ext_object_cache, $wpdb; 
     742function set_transient( $transient, $value, $expiration = 0 ) { 
     743    global $_wp_using_ext_object_cache; 
    745744 
    746745    $value = apply_filters( 'pre_set_transient_' . $transient, $value ); 
    747746 
    748747    if ( $_wp_using_ext_object_cache ) { 
    749         return wp_cache_set($transient, $value, 'transient', $expiration); 
     748        return wp_cache_set( $transient, $value, 'transient', $expiration ); 
    750749    } else { 
    751750        $transient_timeout = '_transient_timeout_' . $transient; 
    752751        $transient = '_transient_' . $transient; 
    753         $safe_transient = esc_sql($transient); 
     752        $safe_transient = esc_sql( $transient ); 
    754753        if ( false === get_option( $safe_transient ) ) { 
    755754            $autoload = 'yes'; 
    756             if ( 0 != $expiration ) { 
     755            if ( $expiration ) { 
    757756                $autoload = 'no'; 
    758757                add_option($transient_timeout, time() + $expiration, '', 'no'); 
     
    760759            return add_option($transient, $value, '', $autoload); 
    761760        } else { 
    762             if ( 0 != $expiration ) 
    763                 update_option($transient_timeout, time() + $expiration); 
     761            if ( $expiration ) 
     762                update_option( $transient_timeout, time() + $expiration ); 
    764763            return update_option($transient, $value); 
    765764        } 
     
    33433342 
    33443343/** 
    3345  * {@internal Missing Short Description}} 
    3346  * 
    3347  * @since 2.8 
    3348  * 
    3349  * @param unknown_type $key 
    3350  * @param unknown_type $default 
    3351  * @param unknown_type $use_cache 
    3352  * @return unknown 
    3353  */ 
    3354 function get_site_option( $key, $default = false, $use_cache = true ) { 
     3344 * Retrieve site option value based on name of option. 
     3345 * 
     3346 * @see get_option() 
     3347 * @package WordPress 
     3348 * @subpackage Option 
     3349 * @since 2.8.0 
     3350 * 
     3351 * @param string $option Name of option to retrieve. Should already be SQL-escaped 
     3352 * @param mixed $default Optional value to return if option doesn't exist. Default false. 
     3353 * @param bool $use_cache Whether to use cache. Multisite only. Default true. 
     3354 * @return mixed Value set for the option. 
     3355 */ 
     3356function get_site_option( $option, $default = false, $use_cache = true ) { 
    33553357    global $wpdb; 
    33563358 
    33573359    // Allow plugins to short-circuit site options. 
    3358     $pre = apply_filters( 'pre_site_option_' . $key, false ); 
     3360    $pre = apply_filters( 'pre_site_option_' . $option, false ); 
    33593361    if ( false !== $pre ) 
    33603362        return $pre; 
    33613363 
    33623364    if ( !is_multisite() ) { 
    3363         $value = get_option($key, $default); 
     3365        $value = get_option($option, $default); 
    33643366    } else { 
    3365         $cache_key = "$wpdb->siteid:$key"; 
     3367        $cache_key = "{$wpdb->siteid}:$option"; 
    33663368        if ( $use_cache ) 
    33673369            $value = wp_cache_get($cache_key, 'site-options'); 
    33683370 
    33693371        if ( false === $value ) { 
    3370             $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ); 
     3372            $value = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); 
    33713373 
    33723374            if ( is_null($value) ) 
     
    33793381    } 
    33803382 
    3381     return apply_filters( 'site_option_' . $key, $value ); 
    3382 } 
    3383  
    3384 /** 
    3385  * {@internal Missing Short Description}} 
    3386  * 
    3387  * @since 2.8 
    3388  * 
    3389  * @param unknown_type $key not to be SQL escaped 
    3390  * @param unknown_type $value not to be SQL escaped 
    3391  * @return unknown 
    3392  */ 
    3393 function add_site_option( $key, $value ) { 
     3383    return apply_filters( 'site_option_' . $option, $value ); 
     3384} 
     3385 
     3386/** 
     3387 * Add a new site option. 
     3388 * 
     3389 * @see add_option() 
     3390 * @package WordPress 
     3391 * @subpackage Option 
     3392 * @since 2.8.0 
     3393 * 
     3394 * @param string $option Name of option to add. Expects to not be SQL escaped. 
     3395 * @param mixed $value Optional. Option value, can be anything. 
     3396 * @return bool False if option was not added and true if option was added. 
     3397 */ 
     3398function add_site_option( $option, $value ) { 
    33943399    global $wpdb; 
    33953400 
    3396     $value = apply_filters( 'pre_add_site_option_' . $key, $value ); 
     3401    $value = apply_filters( 'pre_add_site_option_' . $option, $value ); 
    33973402 
    33983403    if ( !is_multisite() ) { 
    3399         $result =  add_option($key, $value); 
     3404        $result = add_option( $option, $value ); 
    34003405    } else { 
    3401         $cache_key = "{$wpdb->siteid}:$key"; 
    3402  
    3403         if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid ) ) ) 
    3404             return update_site_option( $key, $value ); 
    3405  
    3406         $value = sanitize_option( $key, $value ); 
    3407         wp_cache_set( $cache_key, $value, 'site-options'); 
     3406        $cache_key = "{$wpdb->siteid}:$option"; 
     3407 
     3408        if ( $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) 
     3409            return update_site_option( $option, $value ); 
     3410 
     3411        $value = sanitize_option( $option, $value ); 
     3412        wp_cache_set( $cache_key, $value, 'site-options' ); 
    34083413 
    34093414        $value = maybe_serialize($value); 
    34103415 
    3411         $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $key, 'meta_value' => $value) ); 
    3412     } 
    3413  
    3414     do_action( "add_site_option_{$key}", $key, $value ); 
    3415     do_action( "add_site_option", $key, $value ); 
     3416        $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $value ) ); 
     3417    } 
     3418 
     3419    do_action( "add_site_option_{$option}", $option, $value ); 
     3420    do_action( "add_site_option", $option, $value ); 
    34163421 
    34173422    return $result; 
     
    34193424 
    34203425/** 
    3421  * {@internal Missing Short Description}} 
    3422  * 
    3423  * @since 2.9 
    3424  * 
    3425  * @param unknown_type $key 
    3426  * @return unknown 
    3427  */ 
    3428 function delete_site_option( $key ) { 
     3426 * Removes site option by name. 
     3427 * 
     3428 * @see delete_option() 
     3429 * @package WordPress 
     3430 * @subpackage Option 
     3431 * @since 2.8.0 
     3432 * 
     3433 * @param string $option Name of option to remove. Expected to be SQL-escaped. 
     3434 * @return bool True, if succeed. False, if failure. 
     3435 */ 
     3436function delete_site_option( $option ) { 
    34293437    global $wpdb; 
    34303438 
    3431     //wpmu_protect_special_option( $key ); @todo 
    3432  
    3433     do_action( 'pre_delete_site_option_' . $key ); 
     3439    // ms_protect_special_option( $option ); @todo 
     3440 
     3441    do_action( 'pre_delete_site_option_' . $option ); 
    34343442 
    34353443    if ( !is_multisite() ) { 
    3436         $result = delete_option($key); 
     3444        $result = delete_option( $option ); 
    34373445    } else { 
    3438         $option = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid ) ); 
     3446        $option = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); 
    34393447        if ( is_null( $option ) || !$option->meta_id ) 
    34403448            return false; 
    3441         $cache_key = "{$wpdb->siteid}:$key"; 
     3449        $cache_key = "{$wpdb->siteid}:$option"; 
    34423450        wp_cache_delete( $cache_key, 'site-options' ); 
    34433451 
    3444         $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid ) ); 
    3445     } 
    3446  
    3447     do_action( "delete_site_option_{$key}", $key ); 
    3448     do_action( "delete_site_option", $key ); 
     3452        $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); 
     3453    } 
     3454 
     3455    do_action( "delete_site_option_{$option}", $option ); 
     3456    do_action( "delete_site_option", $option ); 
    34493457    return $result; 
    34503458} 
    34513459 
    34523460/** 
    3453  * {@internal Missing Short Description}} 
    3454  * 
     3461 * Update the value of a site option that was already added. 
     3462 * 
     3463 * @see update_option() 
    34553464 * @since 2.8.0 
    3456  * 
    3457  * @param unknown_type $key not to be SQL escaped 
    3458  * @param unknown_type $value not to be SQL escaped 
    3459  * @return unknown 
    3460  */ 
    3461 function update_site_option( $key, $value ) { 
     3465 * @package WordPress 
     3466 * @subpackage Option 
     3467 * 
     3468 * @param string $option Name of option. Expected to not be SQL-escaped 
     3469 * @param mixed $value Option value. 
     3470 * @return bool False if value was not updated and true if value was updated. 
     3471 */ 
     3472function update_site_option( $option, $value ) { 
    34623473    global $wpdb; 
    34633474 
    3464     $oldvalue = get_site_option( $key ); 
    3465     $value = apply_filters( 'pre_update_site_option_' . $key, $value, $oldvalue ); 
    3466  
    3467     if ( $value == $oldvalue ) 
     3475    $oldvalue = get_site_option( $option ); 
     3476    $value = apply_filters( 'pre_update_site_option_' . $option, $value, $oldvalue ); 
     3477 
     3478    if ( $value === $oldvalue ) 
    34683479        return false; 
    34693480 
    34703481    if ( !is_multisite() ) { 
    3471         $result = update_option($key, $value); 
     3482        $result = update_option( $option, $value ); 
    34723483    } else { 
    3473         $cache_key = "{$wpdb->siteid}:$key"; 
    3474  
    3475         if ( $value && !$wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $key, $wpdb->siteid) ) ) 
    3476             return add_site_option( $key, $value ); 
    3477         $value = sanitize_option( $key, $value ); 
     3484        $cache_key = "{$wpdb->siteid}:$option"; 
     3485 
     3486        if ( $value && !$wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ) ) 
     3487            return add_site_option( $option, $value ); 
     3488        $value = sanitize_option( $option, $value ); 
    34783489        wp_cache_set( $cache_key, $value, 'site-options' ); 
    34793490 
    3480         $value = maybe_serialize($value); 
    3481         $result = $wpdb->update( $wpdb->sitemeta, array('meta_value' => $value), array('site_id' => $wpdb->siteid, 'meta_key' => $key) ); 
    3482     } 
    3483  
    3484     do_action( "update_site_option_{$key}", $key, $value ); 
    3485     do_action( "update_site_option", $key, $value ); 
     3491        $value = maybe_serialize( $value ); 
     3492        $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) ); 
     3493    } 
     3494 
     3495    do_action( "update_site_option_{$option}", $option, $value ); 
     3496    do_action( "update_site_option", $option, $value ); 
    34863497    return $result; 
    34873498} 
     
    34953506 * 
    34963507 * @param string $transient Transient name. Expected to not be SQL-escaped 
    3497  * @return bool true if successful, false otherwise 
    3498  */ 
    3499 function delete_site_transient($transient) { 
    3500     global $_wp_using_ext_object_cache, $wpdb; 
     3508 * @return bool True if successful, false otherwise 
     3509 */ 
     3510function delete_site_transient( $transient ) { 
     3511    global $_wp_using_ext_object_cache; 
    35013512 
    35023513    if ( $_wp_using_ext_object_cache ) { 
    3503         return wp_cache_delete($transient, 'site-transient'); 
     3514        $result = wp_cache_delete( $transient, 'site-transient' ); 
    35043515    } else { 
    3505         $transient = '_site_transient_' . esc_sql($transient); 
    3506         return delete_site_option($transient); 
    3507     } 
     3516        $transient = '_site_transient_' . esc_sql( $transient ); 
     3517        $result = delete_site_option( $transient ); 
     3518    } 
     3519    return $result; 
    35083520} 
    35093521 
     
    35143526 * will be false. 
    35153527 * 
     3528 * @see get_transient() 
    35163529 * @since 2.9.0 
    35173530 * @package WordPress 
     
    35213534 * @return mixed Value of transient 
    35223535 */ 
    3523 function get_site_transient($transient) { 
    3524     global $_wp_using_ext_object_cache, $wpdb; 
     3536function get_site_transient( $transient ) { 
     3537    global $_wp_using_ext_object_cache; 
    35253538 
    35263539    $pre = apply_filters( 'pre_site_transient_' . $transient, false ); 
     
    35293542 
    35303543    if ( $_wp_using_ext_object_cache ) { 
    3531         $value = wp_cache_get($transient, 'site-transient'); 
     3544        $value = wp_cache_get( $transient, 'site-transient' ); 
    35323545    } else { 
    35333546        // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. 
    35343547        $no_timeout = array('update_core', 'update_plugins', 'update_themes'); 
    3535         $transient_option = '_site_transient_' . esc_sql($transient); 
    3536         if ( !in_array($transient, $no_timeout) ) { 
    3537             $transient_timeout = '_site_transient_timeout_' . esc_sql($transient); 
    3538             $timeout = get_site_option($transient_timeout); 
     3548        $transient_option = '_site_transient_' . esc_sql( $transient ); 
     3549        if ( ! in_array( $transient, $no_timeout ) ) { 
     3550            $transient_timeout = '_site_transient_timeout_' . esc_sql( $transient ); 
     3551            $timeout = get_site_option( $transient_timeout ); 
    35393552            if ( false !== $timeout && $timeout < time() ) { 
    3540                 delete_site_option($transient_option); 
    3541                 delete_site_option($transient_timeout); 
     3553                delete_site_option( $transient_option  ); 
     3554                delete_site_option( $transient_timeout ); 
    35423555                return false; 
    35433556            } 
    35443557        } 
    35453558 
    3546         $value = get_site_option($transient_option); 
    3547     } 
    3548  
    3549     return apply_filters('site_transient_' . $transient, $value); 
     3559        $value = get_site_option( $transient_option ); 
     3560    } 
     3561 
     3562    return apply_filters( 'site_transient_' . $transient, $value ); 
    35503563} 
    35513564 
     
    35563569 * it will be serialized before it is set. 
    35573570 * 
     3571 * @see set_transient() 
    35583572 * @since 2.9.0 
    35593573 * @package WordPress 
     
    35653579 * @return bool False if value was not set and true if value was set. 
    35663580 */ 
    3567 function set_site_transient($transient, $value, $expiration = 0) { 
    3568     global $_wp_using_ext_object_cache, $wpdb; 
     3581function set_site_transient( $transient, $value, $expiration = 0 ) { 
     3582    global $_wp_using_ext_object_cache; 
    35693583 
    35703584    if ( $_wp_using_ext_object_cache ) { 
    3571         return wp_cache_set($transient, $value, 'site-transient', $expiration); 
     3585        $result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); 
    35723586    } else { 
    35733587        $transient_timeout = '_site_transient_timeout_' . $transient; 
    35743588        $transient = '_site_transient_' . $transient; 
    3575         $safe_transient = esc_sql($transient); 
     3589        $safe_transient = esc_sql( $transient ); 
    35763590        if ( false === get_site_option( $safe_transient ) ) { 
    3577             if ( 0 != $expiration ) 
    3578                 add_site_option($transient_timeout, time() + $expiration); 
    3579             return add_site_option($transient, $value); 
     3591            if ( $expiration ) 
     3592                add_site_option( $transient_timeout, time() + $expiration ); 
     3593            $result = add_site_option( $transient, $value ); 
    35803594        } else { 
    3581             if ( 0 != $expiration ) 
    3582                 update_site_option($transient_timeout, time() + $expiration); 
    3583             return update_site_option($transient, $value); 
     3595            if ( $expiration ) 
     3596                update_site_option( $transient_timeout, time() + $expiration ); 
     3597            $result = update_site_option( $transient, $value ); 
    35843598        } 
    35853599    } 
     3600    return $result; 
    35863601} 
    35873602 
Note: See TracChangeset for help on using the changeset viewer.