-function get_blogs_of_user( $id, $all = false ) {
- global $wpdb;
-
- $cache_suffix = $all ? '_all' : '_short';
- $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' );
- if ( $return )
- return apply_filters( 'get_blogs_of_user', $return, $id, $all );
-
- $user = get_userdata( (int) $id );
- if ( !$user )
- return false;
-
- $blogs = $match = array();
- $prefix_length = strlen($wpdb->base_prefix);
- foreach ( (array) $user as $key => $value ) {
- if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix )
- continue;
- if ( substr($key, -12, 12) != 'capabilities' )
- continue;
- if ( preg_match( '/^' . $wpdb->base_prefix . '((\d+)_)?capabilities$/', $key, $match ) ) {
- if ( count( $match ) > 2 )
- $blog_id = $match[ 2 ];
- else
- $blog_id = 1;
- $blog = get_blog_details( $blog_id );
- if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) {
- $blogs[ $blog_id ]->userblog_id = $blog_id;
- $blogs[ $blog_id ]->blogname = $blog->blogname;
- $blogs[ $blog_id ]->domain = $blog->domain;
- $blogs[ $blog_id ]->path = $blog->path;
- $blogs[ $blog_id ]->site_id = $blog->site_id;
- $blogs[ $blog_id ]->siteurl = $blog->siteurl;
- }
- }
- }
-
- wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 );
- return apply_filters( 'get_blogs_of_user', $blogs, $id, $all );
-}
-
-function get_active_blog_for_user( $user_id ) { // get an active blog for user - either primary blog or from blogs list
+/**
+ * Get one of a user's active blogs
+ *
+ * Returns the user's primary blog, if she has one and
+ * it is active. If it's inactive, function returns another
+ * active blog of the user. If none are found, the user
+ * is added as a Subscriber to the Dashboard Blog and that blog
+ * is returned.
+ *
+ * @since MU 1.0
+ * @uses get_blogs_of_user()
+ * @uses add_user_to_blog()
+ * @uses get_blog_details()
+ *
+ * @param int $user_id The unique ID of the user
+ * @return object The blog object
+ */
+function get_active_blog_for_user( $user_id ) {