Make WordPress Core


Ignore:
Timestamp:
08/08/2012 05:11:15 PM (12 years ago)
Author:
ryan
Message:

Undeprecate *_blog_option() by popular demand. Put them back in ms-blogs.php since direct inclusion of ms-blogs.php/ms-functions.php is unforntunately common.

see #21432

File:
1 edited

Legend:

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

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