Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Groupblog Plugin questions


David
Participant

@dlabbe

I final got what I was looking for. Here is the code if anyone wants to try it or use it. Paste it in the functions.php of your child themes. What it does is removes the orginal function for the “My Blogs” link in the admin bar and I then made my own function that calls that original function only if the user has a blog. Thus anyone that is just a subscriber to the site will not see the “My Blogs” link in the admin bar (to confuse them).

/* Removes the function from the buddypress/bp-core/bp-core-adminbar.php file in buddypress plugin*/
remove_action(‘bp_adminbar_menus’, ‘bp_adminbar_blogs_menu’, 6);

/*reset the “MY Blogs” link function so that it only shows for users that have blogs and not subscribers*/
function bp_adminbar_mynew_blogs_menu() {
global $bp;

if ( !is_user_logged_in() || !function_exists(‘bp_blogs_install’) )
return false;

if ( !$blogs = wp_cache_get( ‘bp_blogs_of_user_’ . $bp->loggedin_user->id . ‘_inc_hidden’, ‘bp’ ) ) {
$blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
wp_cache_set( ‘bp_blogs_of_user_’ . $bp->loggedin_user->id . ‘_inc_hidden’, $blogs, ‘bp’ );
}

echo ‘
loggedin_user->domain . $bp->blogs->slug . ‘/”>';

_e( ‘My Blogs’, ‘buddypress’ );

echo ‘‘;
echo ‘

    ‘;

    if ( is_array( $blogs ) && (int)$blogs ) {
    $counter = 0;
    foreach ( (array)$blogs as $blog ) {
    $alt = ( 0 == $counter % 2 ) ? ‘ class=”alt”‘ : ”;
    $site_url = esc_attr( $blog->siteurl );

    echo ‘
    ‘;
    echo ‘‘ . esc_html( $blog->name ) . ‘‘;

    echo ‘
        ‘;
        echo ‘
        ‘ . __( ‘Dashboard’, ‘buddypress’ ) . ‘

        ‘;
        echo ‘
        ‘ . __( ‘New Post’, ‘buddypress’ ) . ‘

        ‘;
        echo ‘
        ‘ . __( ‘Manage Posts’, ‘buddypress’ ) . ‘

        ‘;
        echo ‘
        ‘ . __( ‘Manage Comments’, ‘buddypress’ ) . ‘

        ‘;
        echo ‘

    ‘;

    echo ‘

    ‘;
    $counter++;
    }
    }

    $alt = ( 0 == $counter % 2 ) ? ‘ class=”alt”‘ : ”;

    if ( bp_blog_signup_enabled() ) {
    echo ‘
    ‘;
    echo ‘root_domain . ‘/’ . $bp->blogs->slug . ‘/create/”>’ . __( ‘Create a Blog!’, ‘buddypress’ ) . ‘‘;
    echo ‘

    ‘;
    }

    echo ‘

‘;
echo ‘

‘;

}

/*checks to see if the logged in user has any blogs. Saves the array values to $blogs and then saves the blog count to $blogcount. The IF statement then will be true if the value is 1 or more thus showing the link in the admin panel for the “My blogs”*/
$blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id );
$blogCount = ($blogs);

if ( bp_core_is_multisite() && $blogCount >= 1){
add_action( ‘bp_adminbar_menus’, ‘bp_adminbar_mynew_blogs_menu’, 6 );
}

If anyone has a better (cleaner) way to do this please I would love to see it. I am just in the early stage of learning php so any help would be great. Thanks

Skip to toolbar