WordPress.org

Make WordPress Core

Changeset 18662


Ignore:
Timestamp:
09/11/2011 06:53:09 PM (7 years ago)
Author:
nacin
Message:

Allow get_blog_option(null,...) to hit the cache for the current blog. New return values for add_blog_option, update_blog_option, delete_blog_option. Don't set the cache in those functions if add/update/delete_option failed. see #17883.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-blogs.php

    r18601 r18662  
    321321 * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
    322322 *
    323  * @param int $blog_id is the id of the blog.
     323 * @param int $blog_id Optional. Blog ID, can be null to refer to the current blog.
    324324 * @param string $setting Name of option to retrieve. Should already be SQL-escaped.
    325325 * @param string $default (optional) Default value returned if option not found.
     
    328328function get_blog_option( $blog_id, $setting, $default = false ) {
    329329    global $wpdb;
     330
     331    if ( null === $blog_id )
     332        $blog_id = $wpdb->blogid;
    330333
    331334    $key = $blog_id . '-' . $setting . '-blog_option';
     
    381384 * @param string $key The option key
    382385 * @param mixed $value The option value
     386 * @return bool True on success, false on failure.
    383387 */
    384388function add_blog_option( $id, $key, $value ) {
     
    386390
    387391    switch_to_blog($id);
    388     add_option( $key, $value );
     392    $return = add_option( $key, $value );
    389393    restore_current_blog();
    390     wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' );
     394    if ( $return )
     395        wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' );
     396    return $return;
    391397}
    392398
     
    398404 * @param int $id The blog id
    399405 * @param string $key The option key
     406 * @return bool True on success, false on failure.
    400407 */
    401408function delete_blog_option( $id, $key ) {
     
    403410
    404411    switch_to_blog($id);
    405     delete_option( $key );
     412    $return = delete_option( $key );
    406413    restore_current_blog();
    407     wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' );
     414    if ( $return )
     415        wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' );
     416    return $return;
    408417}
    409418
     
    416425 * @param string $key The option key
    417426 * @param mixed $value The option value
     427 * @return bool True on success, false on failrue.
    418428 */
    419429function update_blog_option( $id, $key, $value, $deprecated = null ) {
     
    424434
    425435    switch_to_blog($id);
    426     update_option( $key, $value );
     436    $return = update_option( $key, $value );
    427437    restore_current_blog();
    428438
    429439    refresh_blog_details( $id );
    430440
    431     wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');
     441    if ( $return )
     442        wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');
     443    return $return;
    432444}
    433445
Note: See TracChangeset for help on using the changeset viewer.