Make WordPress Core


Ignore:
Timestamp:
08/03/2012 05:51:42 PM (13 years ago)
Author:
ryan
Message:

Deprecate get_blog_option(), add_blog_option(), update_blog_option(), and delete_blog_option().

Use the regular option functions wrapped in switch_to_blog() and restore_current_blog() instead.

Group multiple operations within a single switch where possible.

fixes #21432

File:
1 edited

Legend:

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

    r21403 r21414  
    223223    }
    224224
    225     $details->blogname      = get_blog_option( $blog_id, 'blogname' );
    226     $details->siteurl       = get_blog_option( $blog_id, 'siteurl' );
    227     $details->post_count    = get_blog_option( $blog_id, 'post_count' );
     225    switch_to_blog( $blog_id );
     226    $details->blogname      = get_option( 'blogname' );
     227    $details->siteurl       = get_option( 'siteurl' );
     228    $details->post_count    = get_option( 'post_count' );
     229    restore_current_blog();
    228230
    229231    $details = apply_filters( 'blog_details', $details );
     
    299301    }
    300302
    301     if ( isset($details[ 'public' ]) )
    302         update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
     303    if ( isset($details[ 'public' ]) ) {
     304        switch_to_blog( $blog_id );
     305        update_option( 'blog_public', $details[ 'public' ] );
     306        restore_current_blog();
     307    }
    303308
    304309    refresh_blog_details($blog_id);
    305310
    306311    return true;
    307 }
    308 
    309 /**
    310  * Retrieve option value for a given blog id based on name of option.
    311  *
    312  * If the option does not exist or does not have a value, then the return value
    313  * will be false. This is useful to check whether you need to install an option
    314  * and is commonly used during installation of plugin options and to test
    315  * whether upgrading is required.
    316  *
    317  * If the option was serialized then it will be unserialized when it is returned.
    318  *
    319  * @since MU
    320  *
    321  * @param int $id A blog ID. Can be null to refer to the current blog.
    322  * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
    323  * @param mixed $default Optional. Default value to return if the option does not exist.
    324  * @return mixed Value set for the option.
    325  */
    326 function get_blog_option( $id, $option, $default = false ) {
    327     $id = (int) $id;
    328 
    329     if ( empty( $id ) )
    330         $id = get_current_blog_id();
    331 
    332     if ( get_current_blog_id() == $id )
    333         return get_option( $option, $default );
    334 
    335     switch_to_blog( $id );
    336     $option = get_option( $option, $default );
    337     restore_current_blog();
    338 
    339     return $option;
    340 }
    341 
    342 /**
    343  * Add a new option for a given blog id.
    344  *
    345  * You do not need to serialize values. If the value needs to be serialized, then
    346  * it will be serialized before it is inserted into the database. Remember,
    347  * resources can not be serialized or added as an option.
    348  *
    349  * You can create options without values and then update the values later.
    350  * Existing options will not be updated and checks are performed to ensure that you
    351  * aren't adding a protected WordPress option. Care should be taken to not name
    352  * options the same as the ones which are protected.
    353  *
    354  * @since MU
    355  *
    356  * @param int $id A blog ID. Can be null to refer to the current blog.
    357  * @param string $option Name of option to add. Expected to not be SQL-escaped.
    358  * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
    359  * @return bool False if option was not added and true if option was added.
    360  */
    361 function add_blog_option( $id, $option, $value ) {
    362     $id = (int) $id;
    363 
    364     if ( empty( $id ) )
    365         $id = get_current_blog_id();
    366 
    367     if ( get_current_blog_id() == $id )
    368         return add_option( $option, $value );
    369 
    370     switch_to_blog( $id );
    371     $return = add_option( $option, $value );
    372     restore_current_blog();
    373 
    374     return $return;
    375 }
    376 
    377 /**
    378  * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
    379  *
    380  * @since MU
    381  *
    382  * @param int $id A blog ID. Can be null to refer to the current blog.
    383  * @param string $option Name of option to remove. Expected to not be SQL-escaped.
    384  * @return bool True, if option is successfully deleted. False on failure.
    385  */
    386 function delete_blog_option( $id, $option ) {
    387     $id = (int) $id;
    388 
    389     if ( empty( $id ) )
    390         $id = get_current_blog_id();
    391 
    392     if ( get_current_blog_id() == $id )
    393         return delete_option( $option );
    394 
    395     switch_to_blog( $id );
    396     $return = delete_option( $option );
    397     restore_current_blog();
    398 
    399     return $return;
    400 }
    401 
    402 /**
    403  * Update an option for a particular blog.
    404  *
    405  * @since MU
    406  *
    407  * @param int $id The blog id
    408  * @param string $option The option key
    409  * @param mixed $value The option value
    410  * @return bool True on success, false on failrue.
    411  */
    412 function update_blog_option( $id, $option, $value, $deprecated = null ) {
    413     $id = (int) $id;
    414 
    415     if ( null !== $deprecated  )
    416         _deprecated_argument( __FUNCTION__, '3.1' );
    417 
    418     if ( get_current_blog_id() == $id )
    419         return update_option( $option, $value );
    420 
    421     switch_to_blog( $id );
    422     $return = update_option( $option, $value );
    423     restore_current_blog();
    424 
    425     refresh_blog_details( $id );
    426 
    427     return $return;
    428312}
    429313
Note: See TracChangeset for help on using the changeset viewer.