get_blogs_of_user

Definition:
function get_blogs_of_user( $id, $all = false ) {}

Parameters

  • $id
  • $all

Defined filters

  • get_blogs_of_user
    apply_filters( 'get_blogs_of_user', $return, $id, $all )
  • get_blogs_of_user
    apply_filters( 'get_blogs_of_user', $blogs, $id, $all )

Source code

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 );

}

1204

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: