Skip to:

Re: Only List Blogs that User is a Member of



I’ve managed to resolve my issue. For anyone who is looking to do something similar, this is what I did.

I was going to resort to creating a custom database query for retrieiving all the users blogs until I dug into the BuddyPress plugin and found the function that is used within the admin area that lists all the blogs that each user is a member of.

I used the ‘get_blogs_of_user’ function found in ms-functions.php:

<br />
<?php<br />
global $bp;<br />
$userID = $bp->loggedin_user->id;<br />
$blogs = get_blogs_of_user( $userID, true );

// Check if blogs have been returned
<ul id="blogs-list" class="item-list">
if ( is_array( $blogs ) ) {
foreach ( (array) $blogs as $key => $val ) {
if($val->userblog_id == 1){ continue; }
$blogLink = "http://".$val->domain . $val->path;
$blogName = $val->blogname;

<div class="item">
<div class="item-title"><a>"><?php echo $blogName; ?> Videos</a></div>
<div class="generic-button blog-button visit">
<a>" class="visit" title="<?php _e( 'View Videos', 'buddypress' ) ?>"><?php _e( 'View Videos', 'buddypress' ) ?></a>
<div class="action">
<?php do_action( 'bp_directory_blogs_actions' ) ?>
<div class="clear"></div>
} // End loop
} // End if
<?php do_action( 'bp_after_directory_blogs_list' ) ?>
<?php bp_blog_hidden_fields() ?>
<?php } else { // If no blogs have been returned ?>
<div id="message" class="info">
<?php _e( 'Sorry, there were no blogs found.', 'buddypress' ) ?>
<?php } // End if ?>

This code will list all of the blogs that the current logged in user is a member of, no matter what role the user has, admin, editor, subscriber etc.

Skip to toolbar