Make WordPress Core


Ignore:
Timestamp:
08/03/2012 05:51:42 PM (12 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-deprecated.php

    r20378 r21414  
    271271    return $url;
    272272}
     273
     274/**
     275 * Retrieve option value for a given blog id based on name of option.
     276 *
     277 * If the option does not exist or does not have a value, then the return value
     278 * will be false. This is useful to check whether you need to install an option
     279 * and is commonly used during installation of plugin options and to test
     280 * whether upgrading is required.
     281 *
     282 * If the option was serialized then it will be unserialized when it is returned.
     283 *
     284 * @since MU
     285 * @deprecated 3.5.0
     286 *
     287 * @param int $id A blog ID. Can be null to refer to the current blog.
     288 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
     289 * @param mixed $default Optional. Default value to return if the option does not exist.
     290 * @return mixed Value set for the option.
     291 */
     292function get_blog_option( $id, $option, $default = false ) {
     293    _deprecated_function( __FUNCTION__, '3.5' );
     294
     295    $id = (int) $id;
     296
     297    if ( empty( $id ) )
     298        $id = get_current_blog_id();
     299
     300    if ( get_current_blog_id() == $id )
     301        return get_option( $option, $default );
     302
     303    switch_to_blog( $id );
     304    $option = get_option( $option, $default );
     305    restore_current_blog();
     306
     307    return $option;
     308}
     309
     310/**
     311 * Add a new option for a given blog id.
     312 *
     313 * You do not need to serialize values. If the value needs to be serialized, then
     314 * it will be serialized before it is inserted into the database. Remember,
     315 * resources can not be serialized or added as an option.
     316 *
     317 * You can create options without values and then update the values later.
     318 * Existing options will not be updated and checks are performed to ensure that you
     319 * aren't adding a protected WordPress option. Care should be taken to not name
     320 * options the same as the ones which are protected.
     321 *
     322 * @since MU
     323 * @deprecated 3.5.0
     324 *
     325 * @param int $id A blog ID. Can be null to refer to the current blog.
     326 * @param string $option Name of option to add. Expected to not be SQL-escaped.
     327 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
     328 * @return bool False if option was not added and true if option was added.
     329 */
     330function add_blog_option( $id, $option, $value ) {
     331    _deprecated_function( __FUNCTION__, '3.5' );
     332
     333    $id = (int) $id;
     334
     335    if ( empty( $id ) )
     336        $id = get_current_blog_id();
     337
     338    if ( get_current_blog_id() == $id )
     339        return add_option( $option, $value );
     340
     341    switch_to_blog( $id );
     342    $return = add_option( $option, $value );
     343    restore_current_blog();
     344
     345    return $return;
     346}
     347
     348/**
     349 * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
     350 *
     351 * @since MU
     352 * @deprecated 3.5.0
     353 *
     354 * @param int $id A blog ID. Can be null to refer to the current blog.
     355 * @param string $option Name of option to remove. Expected to not be SQL-escaped.
     356 * @return bool True, if option is successfully deleted. False on failure.
     357 */
     358function delete_blog_option( $id, $option ) {
     359    _deprecated_function( __FUNCTION__, '3.5' );
     360
     361    $id = (int) $id;
     362
     363    if ( empty( $id ) )
     364        $id = get_current_blog_id();
     365
     366    if ( get_current_blog_id() == $id )
     367        return delete_option( $option );
     368
     369    switch_to_blog( $id );
     370    $return = delete_option( $option );
     371    restore_current_blog();
     372
     373    return $return;
     374}
     375
     376/**
     377 * Update an option for a particular blog.
     378 *
     379 * @since MU
     380 * @deprecated 3.5.0
     381 *
     382 * @param int $id The blog id
     383 * @param string $option The option key
     384 * @param mixed $value The option value
     385 * @return bool True on success, false on failrue.
     386 */
     387function update_blog_option( $id, $option, $value, $deprecated = null ) {
     388    _deprecated_function( __FUNCTION__, '3.5' );
     389
     390    $id = (int) $id;
     391
     392    if ( null !== $deprecated  )
     393        _deprecated_argument( __FUNCTION__, '3.1' );
     394
     395    if ( get_current_blog_id() == $id )
     396        return update_option( $option, $value );
     397
     398    switch_to_blog( $id );
     399    $return = update_option( $option, $value );
     400    restore_current_blog();
     401
     402    refresh_blog_details( $id );
     403
     404    return $return;
     405}
Note: See TracChangeset for help on using the changeset viewer.