WordPress.org

Make WordPress Core

Ticket #14953: 14953-1.diff

File 14953-1.diff, 6.5 KB (added by boonebgorges, 4 years ago)
  • ms-functions.php

     
    77 * @since 3.0.0 
    88 */ 
    99 
     10/** 
     11 * Gets the network's site and user counts. 
     12 * 
     13 * @since MU 1.0 
     14 * @uses get_blog_count() 
     15 * @uses get_user_count() 
     16 * 
     17 * @return array Site and user count for the network. 
     18 */ 
    1019function get_sitestats() { 
    1120        global $wpdb; 
    1221 
     
    1625        return $stats; 
    1726} 
    1827 
     28/** 
     29 * Get the admin for a domain/path combination. 
     30 * 
     31 * @since MU 1.0 
     32 * 
     33 * @param string $sitedomain Optional. Site domain. 
     34 * @param string $path Optional. Site path. 
     35 * @return array The network admins 
     36 */ 
    1937function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { 
    2038        global $wpdb; 
    2139 
     
    3048        return false; 
    3149} 
    3250 
    33 function get_active_blog_for_user( $user_id ) { // get an active blog for user - either primary blog or from blogs list 
     51/** 
     52 * Get one of a user's active blogs 
     53 * 
     54 * Returns the user's primary blog, if she has one and 
     55 * it is active. If it's inactive, function returns another 
     56 * active blog of the user. If none are found, the user 
     57 * is added as a Subscriber to the Dashboard Blog and that blog 
     58 * is returned. 
     59 * 
     60 * @since MU 1.0 
     61 * @uses get_blogs_of_user() 
     62 * @uses get_dashboard_blog() 
     63 * @uses add_user_to_blog() 
     64 * @uses update_user_meta() 
     65 * @uses wp_cache_delete() 
     66 * @uses get_user_meta() 
     67 * @uses get_blog_details() 
     68 * 
     69 * @param int $user_id The unique ID of the user 
     70 * @return object The blog object 
     71 */ 
     72function get_active_blog_for_user( $user_id ) { 
    3473        global $wpdb; 
    3574        $blogs = get_blogs_of_user( $user_id ); 
    3675        if ( empty( $blogs ) ) { 
     
    4483        $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); 
    4584        $details = get_dashboard_blog(); 
    4685        if ( $primary_blog ) { 
    47                 $blogs = get_blogs_of_user( $user_id ); 
    4886                if ( isset( $blogs[ $primary_blog ] ) == false ) { 
    4987                        add_user_to_blog( $details->blog_id, $user_id, 'subscriber' ); 
    5088                        update_user_meta( $user_id, 'primary_blog', $details->blog_id ); 
     
    94132        } 
    95133} 
    96134 
     135/** 
     136 * Find out whether a user is a member of a given blog. 
     137 * 
     138 * @since MU 1.1 
     139 * @uses get_blogs_of_user() 
     140 *  
     141 * @param int $user_id The unique ID of the user 
     142 * @param int $blog Optional. If no blog_id is provided, current site is used 
     143 * @return bool 
     144 */ 
    97145function is_user_member_of_blog( $user_id, $blog_id = 0 ) { 
    98146        $user_id = (int) $user_id; 
    99147        $blog_id = (int) $blog_id; 
     
    110158                return false; 
    111159} 
    112160 
     161/** 
     162 * The number of active users in your installation. 
     163 * 
     164 * This function also saves the count as a site option, 
     165 * which speeds up future lookups. 
     166 * 
     167 * @since MU 2.7 
     168 * @uses update_site_option() 
     169 * 
     170 * @return int 
     171 */ 
    113172function get_user_count() { 
    114173        global $wpdb; 
    115174 
     
    125184        return $count; 
    126185} 
    127186 
     187/** 
     188 * The number of active sites on your installation. 
     189 * 
     190 * This function also saves the count as a site option, 
     191 * which speeds up future lookups. 
     192 * 
     193 * @since MU 1.0 
     194 * @uses update_site_option() 
     195 * 
     196 * @param int $id Optional. A site_id. 
     197 * @return int 
     198 */ 
    128199function get_blog_count( $id = 0 ) { 
    129200        global $wpdb; 
    130201 
     
    143214        return $count; 
    144215} 
    145216 
     217/** 
     218 * Get a blog post from any site on the network. 
     219 * 
     220 * @since MU 1.0 
     221 * 
     222 * @param int $blog_id ID of the blog. 
     223 * @param int $post_id ID of the post you're looking for. 
     224 * @return object The post. 
     225 */ 
    146226function get_blog_post( $blog_id, $post_id ) { 
    147227        global $wpdb; 
    148228 
     
    156236        return $post; 
    157237} 
    158238 
     239/** 
     240 * Add a user to a blog. 
     241 * 
     242 * Use the 'add_user_to_blog' action to fire an event when 
     243 * users are added to a blog. 
     244 * 
     245 * @since MU 1.0 
     246 * @uses switch_to_blog() 
     247 * @uses update_user_meta() 
     248 * @uses wp_cache_delete() 
     249 * @uses restore_current_blog() 
     250 * 
     251 * @param int $blog_id ID of the blog you're adding the user to. 
     252 * @param int $user_id ID of the user you're adding. 
     253 * @param string $role The role you want the user to have 
     254 * @return bool 
     255 */ 
    159256function add_user_to_blog( $blog_id, $user_id, $role ) { 
    160257        switch_to_blog($blog_id); 
    161258 
     
    178275        return true; 
    179276} 
    180277 
     278/** 
     279 * Remove a user from a blog. 
     280 * 
     281 * Use the 'remove_user_from_blog' action to fire an event when 
     282 * users are removed from a blog. 
     283 * 
     284 * Accepts an optional $reassign parameter, if you want to  
     285 * reassign the user's blog posts to another user upon removal. 
     286 * 
     287 * @since MU 1.0 
     288 * @uses switch_to_blog() 
     289 * @uses get_user_meta() 
     290 * @uses get_blogs_of_user() 
     291 * @uses update_user_meta() 
     292 * @uses restore_current_blog() 
     293 * 
     294 * @param int $user_id ID of the user you're removing. 
     295 * @param int $blog_id ID of the blog you're removing the user from. 
     296 * @param string $reassign Optional. A user to whom to reassign posts. 
     297 * @return bool 
     298 */ 
    181299function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') { 
    182300        global $wpdb; 
    183301        switch_to_blog($blog_id); 
     
    225343        restore_current_blog(); 
    226344} 
    227345 
     346/** 
     347 * Create an empty blog. 
     348 * 
     349 * @since MU 1.0 
     350 * @uses switch_to_blog() 
     351 * @uses install_blog() 
     352 * @uses restore_current_blog() 
     353 * 
     354 * @param string $domain The new blog's domain. 
     355 * @param string $path The new blog's path. 
     356 * @param string $string The new blog's title. 
     357 * @param int $site Optional. Defaults to 1. 
     358 * @return int $blog_id The ID of the newly created blog 
     359 */ 
    228360function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { 
    229361        $domain                 = addslashes( $domain ); 
    230362        $weblog_title   = addslashes( $weblog_title ); 
     
    250382        return $blog_id; 
    251383} 
    252384 
     385/** 
     386 * Get the permalink for a post on another blog. 
     387 * 
     388 * @since MU 1.0 
     389 * @uses wp_cache_get() 
     390 * @uses switch_to_blog() 
     391 * @uses restore_current_blog() 
     392 * @uses wp_cache_add() 
     393 * 
     394 * @param int $_blog_id ID of the source blog. 
     395 * @param int $post_id ID of the desired post. 
     396 * @return string $link The post's permalink 
     397 */ 
    253398function get_blog_permalink( $_blog_id, $post_id ) { 
    254399        $key = "{$_blog_id}-{$post_id}-blog_permalink"; 
    255400        $link = wp_cache_get( $key, 'site-options' ); 
     
    262407        return $link; 
    263408} 
    264409 
     410/** 
     411 * Get a blog's numeric ID from its URL. 
     412 * 
     413 * On a subdirectory installation like example.com/blog1/, 
     414 * $domain will be the root 'example.com' and $path the 
     415 * subdirectory '/blog1/'. With subdomains like blog1.example.com, 
     416 * $domain is 'blog1.example.com' and $path is '/'. 
     417 * 
     418 * @since MU 2.6.5 
     419 * @uses wp_cache_get() 
     420 * @uses wp_cache_set() 
     421 * 
     422 * @param string $domain 
     423 * @param string $path Optional. Not required for subdomain installations. 
     424 * @return int $id 
     425 */ 
    265426function get_blog_id_from_url( $domain, $path = '/' ) { 
    266427        global $wpdb; 
    267428