Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r15452 r17005  
    66 * @package WordPress
    77 * @subpackage Multisite
    8  * @since 3.0.0
    9  */
    10 
    11 // @todo use update_blog_details
     8 * @since MU
     9 */
     10
     11/**
     12 * Update the last_updated field for the current blog.
     13 *
     14 * @since MU
     15 */
    1216function wpmu_update_blogs_date() {
    1317    global $wpdb;
    1418
     19    // TODO: use update_blog_details
     20
    1521    $wpdb->update( $wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $wpdb->blogid) );
    1622    refresh_blog_details( $wpdb->blogid );
     
    1925}
    2026
     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 */
    2135function get_blogaddress_by_id( $blog_id ) {
    2236    $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
     
    2438}
    2539
     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 */
    2648function get_blogaddress_by_name( $blogname ) {
    2749    global $current_site;
     
    3961}
    4062
    41 function get_blogaddress_by_domain( $domain, $path ){
     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 */
     72function get_blogaddress_by_domain( $domain, $path ) {
    4273    if ( is_subdomain_install() ) {
    4374        $url = "http://".$domain.$path;
     
    5687}
    5788
     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 */
    5897function get_id_from_blogname( $name ) {
    5998    global $wpdb, $current_site;
     
    77116 * Retrieve the details for a blog from the blogs table and blog options.
    78117 *
    79  * @since 3.0.0
     118 * @since MU
     119 *
    80120 * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
    81121 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
     
    203243 * Clear the blog details cache.
    204244 *
    205  * @since 3.0.0
     245 * @since MU
    206246 *
    207247 * @param int $blog_id Blog ID
     
    221261 * Update the details for a blog. Updates the blogs table for a given blog id.
    222262 *
    223  * @since 3.0.0
     263 * @since MU
    224264 *
    225265 * @param int $blog_id Blog ID
     
    261301
    262302    if ( isset($details[ 'public' ]) )
    263         update_blog_option( $blog_id, 'blog_public', $details[ 'public' ], false );
     303        update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
    264304
    265305    refresh_blog_details($blog_id);
     
    281321 * The 'option_$option' filter in get_option() is not called.
    282322 *
    283  * @since NA
    284  * @package WordPress MU
    285  * @subpackage Option
     323 * @since MU
    286324 * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
    287325 *
    288326 * @param int $blog_id is the id of the blog.
    289  * @param string $setting Name of option to retrieve. Should already be SQL-escaped
     327 * @param string $setting Name of option to retrieve. Should already be SQL-escaped.
    290328 * @param string $default (optional) Default value returned if option not found.
    291329 * @return mixed Value set for the option.
     
    335373        $value = untrailingslashit( $value );
    336374
    337     if (! @unserialize( $value ) )
    338         $value = stripslashes( $value );
    339 
    340375    return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id );
    341376}
    342377
     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 */
    343387function add_blog_option( $id, $key, $value ) {
    344388    $id = (int) $id;
     
    350394}
    351395
     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 */
    352404function delete_blog_option( $id, $key ) {
    353405    $id = (int) $id;
     
    359411}
    360412
    361 function update_blog_option( $id, $key, $value, $refresh = true ) {
     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 */
     422function update_blog_option( $id, $key, $value, $deprecated = null ) {
    362423    $id = (int) $id;
     424
     425    if ( null !== $deprecated  )
     426        _deprecated_argument( __FUNCTION__, '3.1' );
    363427
    364428    switch_to_blog($id);
     
    366430    restore_current_blog();
    367431
    368     if ( $refresh == true )
    369         refresh_blog_details( $id );
     432    refresh_blog_details( $id );
     433
    370434    wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options');
    371435}
    372436
     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 */
    373454function switch_to_blog( $new_blog, $validate = false ) {
    374455    global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
     
    407488        $wpdb->suppress_errors( false );
    408489    }
    409  
     490
    410491    if ( did_action('init') ) {
    411         $current_user = wp_get_current_user(); 
     492        $current_user = wp_get_current_user();
    412493        if ( is_object( $current_user ) )
    413494            $current_user->for_blog( $blog_id );
     
    424505            wp_cache_add_global_groups( $global_groups );
    425506        else
    426             wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient', 'global-posts' ) );
     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' ) );
    427508        wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    428509    }
     
    433514}
    434515
     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 */
    435524function restore_current_blog() {
    436525    global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
     
    480569            wp_cache_add_global_groups( $global_groups );
    481570        else
    482             wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient' ) );
     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' ) );
    483572        wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
    484573    }
     
    491580}
    492581
     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 */
    493590function is_archived( $id ) {
    494591    return get_blog_status($id, 'archived');
    495592}
    496593
     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 */
    497603function update_archived( $id, $archived ) {
    498604    update_blog_status($id, 'archived', $archived);
     
    503609 * Update a blog details field.
    504610 *
    505  * @since 3.0.0
     611 * @since MU
    506612 *
    507613 * @param int $blog_id BLog ID
    508614 * @param string $pref A field name
    509615 * @param string $value Value for $pref
    510  * @param bool $refresh Whether to refresh the blog details cache. Default is true.
    511  */
    512 function update_blog_status( $blog_id, $pref, $value, $refresh = true ) {
     616 * @return string $value
     617 */
     618function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
    513619    global $wpdb;
     620
     621    if ( null !== $deprecated  )
     622        _deprecated_argument( __FUNCTION__, '3.1' );
    514623
    515624    if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
     
    518627    $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
    519628
    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     }
     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 );
    529639
    530640    return $value;
    531641}
    532642
     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 */
    533652function get_blog_status( $id, $pref ) {
    534653    global $wpdb;
     
    541660}
    542661
     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 */
    543672function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
    544673    global $wpdb;
     674
     675    if ( ! empty( $deprecated ) )
     676        _deprecated_argument( __FUNCTION__, 'MU' ); // never used
     677
    545678    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 );
    546679}
Note: See TracChangeset for help on using the changeset viewer.