Ticket #14953: 14953-1.diff
File 14953-1.diff, 6.5 KB (added by , 15 years ago) |
---|
-
ms-functions.php
7 7 * @since 3.0.0 8 8 */ 9 9 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 */ 10 19 function get_sitestats() { 11 20 global $wpdb; 12 21 … … 16 25 return $stats; 17 26 } 18 27 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 */ 19 37 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { 20 38 global $wpdb; 21 39 … … 30 48 return false; 31 49 } 32 50 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 */ 72 function get_active_blog_for_user( $user_id ) { 34 73 global $wpdb; 35 74 $blogs = get_blogs_of_user( $user_id ); 36 75 if ( empty( $blogs ) ) { … … 44 83 $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); 45 84 $details = get_dashboard_blog(); 46 85 if ( $primary_blog ) { 47 $blogs = get_blogs_of_user( $user_id );48 86 if ( isset( $blogs[ $primary_blog ] ) == false ) { 49 87 add_user_to_blog( $details->blog_id, $user_id, 'subscriber' ); 50 88 update_user_meta( $user_id, 'primary_blog', $details->blog_id ); … … 94 132 } 95 133 } 96 134 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 */ 97 145 function is_user_member_of_blog( $user_id, $blog_id = 0 ) { 98 146 $user_id = (int) $user_id; 99 147 $blog_id = (int) $blog_id; … … 110 158 return false; 111 159 } 112 160 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 */ 113 172 function get_user_count() { 114 173 global $wpdb; 115 174 … … 125 184 return $count; 126 185 } 127 186 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 */ 128 199 function get_blog_count( $id = 0 ) { 129 200 global $wpdb; 130 201 … … 143 214 return $count; 144 215 } 145 216 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 */ 146 226 function get_blog_post( $blog_id, $post_id ) { 147 227 global $wpdb; 148 228 … … 156 236 return $post; 157 237 } 158 238 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 */ 159 256 function add_user_to_blog( $blog_id, $user_id, $role ) { 160 257 switch_to_blog($blog_id); 161 258 … … 178 275 return true; 179 276 } 180 277 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 */ 181 299 function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') { 182 300 global $wpdb; 183 301 switch_to_blog($blog_id); … … 225 343 restore_current_blog(); 226 344 } 227 345 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 */ 228 360 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { 229 361 $domain = addslashes( $domain ); 230 362 $weblog_title = addslashes( $weblog_title ); … … 250 382 return $blog_id; 251 383 } 252 384 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 */ 253 398 function get_blog_permalink( $_blog_id, $post_id ) { 254 399 $key = "{$_blog_id}-{$post_id}-blog_permalink"; 255 400 $link = wp_cache_get( $key, 'site-options' ); … … 262 407 return $link; 263 408 } 264 409 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 */ 265 426 function get_blog_id_from_url( $domain, $path = '/' ) { 266 427 global $wpdb; 267 428