WordPress.org

Make WordPress Core

Changeset 21480


Ignore:
Timestamp:
08/08/2012 05:11:15 PM (7 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

Location:
trunk/wp-includes
Files:
2 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 *
  • trunk/wp-includes/ms-deprecated.php

    r21414 r21480  
    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  */
    292 function 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  */
    330 function 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  */
    358 function 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  */
    387 function 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.