WordPress.org

Make WordPress Core

Ticket #14953: ms-blogs.2.diff

File ms-blogs.2.diff, 7.7 KB (added by scribu, 4 years ago)

Set @since MU. More warnings on switch_to_blog()

  • wp-includes/ms-blogs.php

     
    55 * 
    66 * @package WordPress 
    77 * @subpackage Multisite 
    8  * @since 3.0.0 
     8 * @since MU 
    99 */ 
    1010 
    11 // @todo use update_blog_details 
     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 ); 
    1723 
    1824        do_action( 'wpmu_blog_updated', $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! 
    2337        return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path ); 
    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; 
    2850 
     
    3860        return esc_url( $url . '/' ); 
    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; 
    4475        } else { 
     
    5586        return esc_url( $url ); 
    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; 
    6099        $blog_id = wp_cache_get( "get_id_from_blogname_" . $name, 'blog-details' ); 
     
    76115/** 
    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. 
    82122 * @return object Blog details. 
     
    202242/** 
    203243 * Clear the blog details cache. 
    204244 * 
    205  * @since 3.0.0 
     245 * @since MU 
    206246 * 
    207247 * @param int $blog_id Blog ID 
    208248 */ 
     
    220260/** 
    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 
    226266 * @param array $details Array of details keyed by blogs table field names. 
     
    280320 * $blog_id. It returns $value. 
    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. 
    292330 */ 
     
    340378        return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id ); 
    341379} 
    342380 
     381/** 
     382 * Add an option for a particular blog. 
     383 * 
     384 * @since MU 
     385 * 
     386 * @param int $id The blog id 
     387 * @param string $key The option key 
     388 * @param mixed $value The option value 
     389 */ 
    343390function add_blog_option( $id, $key, $value ) { 
    344391        $id = (int) $id; 
    345392 
     
    349396        wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options' ); 
    350397} 
    351398 
     399/** 
     400 * Delete an option for a particular blog. 
     401 * 
     402 * @since MU 
     403 * 
     404 * @param int $id The blog id 
     405 * @param string $key The option key 
     406 */ 
    352407function delete_blog_option( $id, $key ) { 
    353408        $id = (int) $id; 
    354409 
     
    358413        wp_cache_set( $id."-".$key."-blog_option", '', 'site-options' ); 
    359414} 
    360415 
     416/** 
     417 * Update an option for a particular blog. 
     418 * 
     419 * @since MU 
     420 * 
     421 * @param int $id The blog id 
     422 * @param string $key The option key 
     423 * @param mixed $value The option value 
     424 * @param bool $refresh Wether to refresh blog details or not 
     425 */ 
    361426function update_blog_option( $id, $key, $value, $refresh = true ) { 
    362427        $id = (int) $id; 
    363428 
     
    370435        wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options'); 
    371436} 
    372437 
     438/** 
     439 * Switch the current blog. 
     440 * 
     441 * This function is useful if you need to pull posts, or other information, 
     442 * from other blogs. You can switch back afterwards using restore_current_blog(). 
     443 * 
     444 * Things that aren't switched: 
     445 *  - autoloaded options. See #14992 
     446 *  - plugins. See #14941 
     447 * 
     448 * @see restore_current_blog() 
     449 * @since MU 
     450 * 
     451 * @param int $new_blog The id of the blog you want to switch to. Default: current blog 
     452 * @param bool $validate Wether to check if $new_blog exists before proceeding 
     453 * @return bool True on success, False if the validation failed 
     454 */ 
    373455function switch_to_blog( $new_blog, $validate = false ) { 
    374456        global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; 
    375457 
     
    432514        return true; 
    433515} 
    434516 
     517/** 
     518 * Restore the current blog, after calling switch_to_blog() 
     519 * 
     520 * @see switch_to_blog() 
     521 * @since MU 
     522 * 
     523 * @return bool True on success, False if we're already on the current blog 
     524 */ 
    435525function restore_current_blog() { 
    436526        global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; 
    437527 
     
    490580        return true; 
    491581} 
    492582 
     583/** 
     584 * Check if a particular blog is archived. 
     585 * 
     586 * @since MU 
     587 * 
     588 * @param int $id The blog id 
     589 * @return string Wether the blog is archived or not 
     590 */ 
    493591function is_archived( $id ) { 
    494592        return get_blog_status($id, 'archived'); 
    495593} 
    496594 
     595/** 
     596 * Update the 'archived' status of a particular blog. 
     597 * 
     598 * @since MU 
     599 * 
     600 * @param int $id The blog id 
     601 * @param string $archived The new status 
     602 * @return string $archived 
     603 */ 
    497604function update_archived( $id, $archived ) { 
    498605        update_blog_status($id, 'archived', $archived); 
    499606        return $archived; 
     
    502609/** 
    503610 * Update a blog details field. 
    504611 * 
    505  * @since 3.0.0 
     612 * @since MU 
    506613 * 
    507614 * @param int $blog_id BLog ID 
    508615 * @param string $pref A field name 
    509616 * @param string $value Value for $pref 
    510617 * @param bool $refresh Whether to refresh the blog details cache. Default is true. 
     618 * @return string $value 
    511619 */ 
    512620function update_blog_status( $blog_id, $pref, $value, $refresh = true ) { 
    513621        global $wpdb; 
     
    530638        return $value; 
    531639} 
    532640 
     641/** 
     642 * Get a blog details field. 
     643 * 
     644 * @since MU 
     645 * 
     646 * @param int $id The blog id 
     647 * @param string $pref A field name 
     648 * @return bool $value 
     649 */ 
    533650function get_blog_status( $id, $pref ) { 
    534651        global $wpdb; 
    535652 
     
    540657        return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) ); 
    541658} 
    542659 
     660/** 
     661 * Get a list of most recently updated blogs. 
     662 * 
     663 * @since MU 
     664 *  
     665 * @param $deprecated Not used 
     666 * @param int $start The offset 
     667 * @param int $quantity The maximum number of blogs to retrieve. Default is 40. 
     668 * @return array The list of blogs 
     669 */ 
    543670function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { 
    544671        global $wpdb; 
    545672        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 );