Skip to:
Content
Pages
Categories
Search
Top
Bottom

Only List Blogs that User is a Member of

  • I’m creating a multi-user, multi-site blog. I need the users to be members of certain blogs and that they can only login and access the blogs they are members of.

    I’ve managed to get it so the homepage of the site is accessible and the rest of the blogs within are password protected.

    When the user logs in, I would like them to be presented with a list of the blogs that they are members of, I don’t care whether they are Admins or just Subscribers, I would like them to be listed.

    Any have any ideas of how I could do this?

Viewing 1 replies (of 1 total)
  • 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
    if(!empty($blogs)){
    ?>
    <ul id="blogs-list" class="item-list">
    <?php
    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;
    ?>

    <li>
    <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>
    </div>
    <div class="action">
    <?php do_action( 'bp_directory_blogs_actions' ) ?>
    </div>
    <div class="clear"></div>
    </li>
    <?php
    } // 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' ) ?>
    </div>
    <?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.

Viewing 1 replies (of 1 total)
  • The topic ‘Only List Blogs that User is a Member of’ is closed to new replies.
Skip to toolbar