Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17005 r15452  
    66 * @package WordPress
    77 * @subpackage Multisite
    8  * @since MU
     8 * @since 3.0.0
    99 */
    1010
    11 /**
    12  * Update the last_updated field for the current blog.
    13  *
    14  * @since MU
    15  */
     11// @todo use update_blog_details
    1612function wpmu_update_blogs_date() {
    1713    global $wpdb;
    18 
    19     // TODO: use update_blog_details
    2014
    2115    $wpdb->update( $wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $wpdb->blogid) );
     
    2519}
    2620
    27 /**
    28  * Get a full blog URL, given a blog id.
    29  *
    30  * @since MU
    31  *
    32  * @param int $blog_id Blog ID
    33  * @return string
    34  */
    3521function get_blogaddress_by_id( $blog_id ) {
    3622    $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
     
    3824}
    3925
    40 /**
    41  * Get a full blog URL, given a blog name.
    42  *
    43  * @since MU
    44  *
    45  * @param string $blogname The (subdomain or directory) name
    46  * @return string
    47  */
    4826function get_blogaddress_by_name( $blogname ) {
    4927    global $current_site;
     
    6139}
    6240
    63 /**
    64  * Get a full blog URL, given a domain and a path.
    65  *
    66  * @since MU
    67  *
    68  * @param string $domain
    69  * @param string $path
    70  * @return string
    71  */
    72 function get_blogaddress_by_domain( $domain, $path ) {
     41function get_blogaddress_by_domain( $domain, $path ){
    7342    if ( is_subdomain_install() ) {
    7443        $url = "http://".$domain.$path;
     
    8756}
    8857
    89 /**
    90  * Given a blog's (subdomain or directory) name, retrieve it's id.
    91  *
    92  * @since MU
    93  *
    94  * @param string $name
    95  * @return int A blog id
    96  */
    9758function get_id_from_blogname( $name ) {
    9859    global $wpdb, $current_site;
     
    11677 * Retrieve the details for a blog from the blogs table and blog options.
    11778 *
    118  * @since MU
    119  *
     79 * @since 3.0.0
    12080 * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
    12181 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
     
    243203 * Clear the blog details cache.
    244204 *
    245  * @since MU
     205 * @since 3.0.0
    246206 *
    247207 * @param int $blog_id Blog ID
     
    261221 * Update the details for a blog. Updates the blogs table for a given blog id.
    262222 *
    263  * @since MU
     223 * @since 3.0.0
    264224 *
    265225 * @param int $blog_id Blog ID
     
    301261
    302262    if ( isset($details[ 'public' ]) )
    303         update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
     263        update_blog_option( $blog_id, 'blog_public', $details[ 'public' ], false );
    304264
    305265    refresh_blog_details($blog_id);
     
    321281 * The 'option_$option' filter in get_option() is not called.
    322282 *
    323  * @since MU
     283 * @since NA
     284 * @package WordPress MU
     285 * @subpackage Option
    324286 * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
    325287 *
    326288 * @param int $blog_id is the id of the blog.
    327  * @param string $setting Name of option to retrieve. Should already be SQL-escaped.
     289 * @param string $setting Name of option to retrieve. Should already be SQL-escaped
    328290 * @param string $default (optional) Default value returned if option not found.
    329291 * @return mixed Value set for the option.
     
    373335        $value = untrailingslashit( $value );
    374336
     337    if (! @unserialize( $value ) )
     338        $value = stripslashes( $value );
     339
    375340    return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id );
    376341}
    377342
    378 /**
    379  * Add an option for a particular blog.
    380  *
    381  * @since MU
    382  *
    383  * @param int $id The blog id
    384  * @param string $key The option key
    385  * @param mixed $value The option value
    386  */
    387343function add_blog_option( $id, $key, $value ) {
    388344    $id = (int) $id;
     
    394350}
    395351
    396 /**
    397  * Delete an option for a particular blog.
    398  *
    399  * @since MU
    400  *
    401  * @param int $id The blog id
    402  * @param string $key The option key
    403  */
    404352function delete_blog_option( $id, $key ) {
    405353    $id = (int) $id;
     
    411359}
    412360
    413 /**
    414  * Update an option for a particular blog.
    415  *
    416  * @since MU
    417  *
    418  * @param int $id The blog id
    419  * @param string $key The option key
    420  * @param mixed $value The option value
    421  */
    422 function update_blog_option( $id, $key, $value, $deprecated = null ) {
     361function update_blog_option( $id, $key, $value, $refresh = true ) {
    423362    $id = (int) $id;
    424 
    425     if ( null !== $deprecated  )
    426         _deprecated_argument( __FUNCTION__, '3.1' );
    427363
    428364    switch_to_blog($id);
     
    430366    restore_current_blog();
    431367
    432     refresh_blog_details( $id );
    433 
     368    if ( $refresh == true )
     369        refresh_blog_details( $id );
    434370    wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options');
    435371}
    436372
    437 /**
    438  * Switch the current blog.
    439  *
    440  * This function is useful if you need to pull posts, or other information,
    441  * from other blogs. You can switch back afterwards using restore_current_blog().
    442  *
    443  * Things that aren't switched:
    444  *  - autoloaded options. See #14992
    445  *  - plugins. See #14941
    446  *
    447  * @see restore_current_blog()
    448  * @since MU
    449  *
    450  * @param int $new_blog The id of the blog you want to switch to. Default: current blog
    451  * @param bool $validate Whether to check if $new_blog exists before proceeding
    452  * @return bool True on success, False if the validation failed
    453  */
    454373function switch_to_blog( $new_blog, $validate = false ) {
    455374    global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
     
    488407        $wpdb->suppress_errors( false );
    489408    }
    490 
     409 
    491410    if ( did_action('init') ) {
    492         $current_user = wp_get_current_user();
     411        $current_user = wp_get_current_user(); 
    493412        if ( is_object( $current_user ) )
    494413            $current_user->for_blog( $blog_id );
     
    505424            wp_cache_add_global_groups( $global_groups );
    506425        else
    507             wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
     426            wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient', 'global-posts' ) );
    508427        wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    509428    }
     
    514433}
    515434
    516 /**
    517  * Restore the current blog, after calling switch_to_blog()
    518  *
    519  * @see switch_to_blog()
    520  * @since MU
    521  *
    522  * @return bool True on success, False if we're already on the current blog
    523  */
    524435function restore_current_blog() {
    525436    global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
     
    569480            wp_cache_add_global_groups( $global_groups );
    570481        else
    571             wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
     482            wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient' ) );
    572483        wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    573484    }
     
    580491}
    581492
    582 /**
    583  * Check if a particular blog is archived.
    584  *
    585  * @since MU
    586  *
    587  * @param int $id The blog id
    588  * @return string Whether the blog is archived or not
    589  */
    590493function is_archived( $id ) {
    591494    return get_blog_status($id, 'archived');
    592495}
    593496
    594 /**
    595  * Update the 'archived' status of a particular blog.
    596  *
    597  * @since MU
    598  *
    599  * @param int $id The blog id
    600  * @param string $archived The new status
    601  * @return string $archived
    602  */
    603497function update_archived( $id, $archived ) {
    604498    update_blog_status($id, 'archived', $archived);
     
    609503 * Update a blog details field.
    610504 *
    611  * @since MU
     505 * @since 3.0.0
    612506 *
    613507 * @param int $blog_id BLog ID
    614508 * @param string $pref A field name
    615509 * @param string $value Value for $pref
    616  * @return string $value
     510 * @param bool $refresh Whether to refresh the blog details cache. Default is true.
    617511 */
    618 function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
    619     global $wpdb;
    620 
    621     if ( null !== $deprecated  )
    622         _deprecated_argument( __FUNCTION__, '3.1' );
     512function update_blog_status( $blog_id, $pref, $value, $refresh = true ) {
     513    global $wpdb;
    623514
    624515    if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
     
    627518    $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
    628519
    629     refresh_blog_details($blog_id);
    630 
    631     if ( 'spam' == $pref )
    632         ( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) : do_action( 'make_ham_blog', $blog_id );
    633     elseif ( 'mature' == $pref )
    634         ( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
    635     elseif ( 'archived' == $pref )
    636         ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
    637     elseif ( 'archived' == $pref )
    638         ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
     520    if ( $refresh )
     521        refresh_blog_details($blog_id);
     522
     523    if ( $pref == 'spam' ) {
     524        if ( $value == 1 )
     525            do_action( "make_spam_blog", $blog_id );
     526        else
     527            do_action( "make_ham_blog", $blog_id );
     528    }
    639529
    640530    return $value;
    641531}
    642532
    643 /**
    644  * Get a blog details field.
    645  *
    646  * @since MU
    647  *
    648  * @param int $id The blog id
    649  * @param string $pref A field name
    650  * @return bool $value
    651  */
    652533function get_blog_status( $id, $pref ) {
    653534    global $wpdb;
     
    660541}
    661542
    662 /**
    663  * Get a list of most recently updated blogs.
    664  *
    665  * @since MU
    666  *
    667  * @param mixed $deprecated Not used
    668  * @param int $start The offset
    669  * @param int $quantity The maximum number of blogs to retrieve. Default is 40.
    670  * @return array The list of blogs
    671  */
    672543function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
    673544    global $wpdb;
    674 
    675     if ( ! empty( $deprecated ) )
    676         _deprecated_argument( __FUNCTION__, 'MU' ); // never used
    677 
    678545    return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A );
    679546}
Note: See TracChangeset for help on using the changeset viewer.