Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

How to definitively display Buddypress avatars in BBPress??? (30 posts)

Started 2 years ago by: tinabeans

  • I know there have been a million and one posts/questions about this. The trouble is, there is a lot of conflicting instructions… and it is scattered all over the place. I feel like I am very close, but cannot for the life of me get this to work…

    So far, I’ve successfully done the Wordpress “deep integration.” I tested this by putting some random Buddypress tags in BBpress template files. They worked fine. Here’s where I’m running into some trouble:

    I am trying to display the exact same avatar that appears in Buddypress for a particular user in BBPress as well. I tested the following template tags on my profile.php (in my BBpress theme):

    bp_member_avatar(); no result (blank)
    bp_core_fetch_avatar(userid); -> no result (blank)
    bp_core_get_avatar(userid); -> function undefined
    get_avatar(userid); -> this shows the wordpress avatar, not the buddypress one

    Help. Which is the correct tag to use? I need to be able to display an avatar based on user id. That is all. Surely that’s not impossible?

    If there are no existing tags that will do this, can someone just tell me how to do a database query? I found this post http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/where-are-the-avatars/ but don’t know where to go from there…

    Thanks in advance!

    Running: WP MU 2.9.2, Buddypress 1.2.3, and BBPress 1.0.2

  • Profile picture of r-a-y r-a-y said 2 years ago:

    @tinabeans – Try this:

    http://bbpress.org/forums/topic/avatar-sharing-between-buddypress-and-bbpress

  • I’ve seen that one. When I try that, I get:

    Fatal error: Call to undefined function bp_core_get_avatar() in /data/19/1/45/55/1860544/user/2020360/htdocs/peersforum/discuss/forum/my-templates/bbpress-peersforum/profile.php on line 4

  • Profile picture of r-a-y r-a-y said 2 years ago:

    @tinabeans – just tested the following snippet:

    echo bp_core_fetch_avatar( 'item_id='.get_post_author_id() );

    This is working for me on a deep-integrated external bbPress install. Let me know if this works for you.

  • YOU ARE AMAZING! You know, you just redeemed my whole afternoon of work. Hooray =) I owe you a beer for that one!

    Well… here’s the postscript. It all comes back to one thing I’ve been frustrated with: why is there no good documentation on BP or BBpress template tags? I had to search the code repo to find a hint that bp_core_get_avatar() was deprecated in favor of bp_core_fetch_avatar(), and after that still didn’t know that I had to put “item_id=” before the ID in the argument string. Not sure how I would have figured that one out on my own, given my apparent lack of PHP reading skills.

    If someone knows a secret source of well-documented template tags, do let me know. All I’ve found so far is http://codex.buddypress.org/developer-discussions/buddypress-template-tags/ for Buddypress (which doesn’t even have bp_core_fetch_avatar() listed). Bummer.

    Okay, I do have one last question for you: what other params does bp_core_fetch_avatar() take, and how can I find out? for instance, can I specify a different size of avatar?

  • Profile picture of r-a-y r-a-y said 2 years ago:

    That’s because the documentation relies on users like you and me (for both bbPress and BuddyPress).

    Most of the template tags you can find in /bp-xxx-templatetags.php in the BuddyPress folder. It’s well organized enough to read and I usually just dig through the code to find what I need.

    Btw… I do take donations! You could consider that beer money ;)

  • Nevermind, I googled for that function and found the SVN repo where that function is defined: http://bp-dev.org/phpxref/nav.html?_functions/index.html

    The params it takes are:

    $defaults = array(
    ‘item_id’ => false,
    ‘object’ => ‘user’, // user OR group OR blog OR custom type (if you use filters)
    ‘type’ => ‘thumb’,
    ‘avatar_dir’ => ‘avatars’,
    ‘width’ => false,
    ‘height’ => false,
    ‘class’ => ‘avatar’,
    ‘id’ => false,
    ‘alt’ => __( ‘Avatar Image’, ‘buddypress’ ),
    );

    … and the params can be fed into bp_core_fetch_avatar() in the form of “name=value&name=value” pairs as a string.

    Hope this helps someone else who is having the same issue. =)

  • I actually couldn’t find the template tags php file in my buddypress folder. I think I’ll just use the SVN for now. It has a nice search function.

    Beer funds sent. Thanks again~

  • Profile picture of r-a-y r-a-y said 2 years ago:

    Yup, that function can be found in /bp-core/bp-core-avatars.php

    Check out some of the other template tag functions in:

    /bp-core/bp-core-templatetags.php
    /bp-groups/bp-groups-templatetags.php
    /bp-friends/bp-friends-templatetags.php

    etc.

    Btw, thanks for the funds ;)

  • Profile picture of jillsays jillsays said 1 year, 12 months ago:

    @r-a-y,
    is it possible to show buddypress avatars on bbpress WITHOUT deep integration? i have a high traffic site, and i’m already low on memory!

  • Profile picture of r-a-y r-a-y said 1 year, 12 months ago:

    @jillsays – As long as you have your users integrated between WP and bbPress, it’s definitely possible.

    I don’t have any code to give you at the moment… but the way I’d go about it is, I’d write a function in bbPress to find your BuddyPress avatar directory, then you could do a check to see if the user_id directory exists… if so, spit out the BP avatar URL in bbPress.

  • Profile picture of jillsays jillsays said 1 year, 12 months ago:

    @r-a-y — any help you could give me would be tremendous. I’ve been at it for days and am about to crack!
    Writing functions is way out of my league, but if you’d be kind enough as to help, there’s beer money in it for you! :)
    Jill

  • Profile picture of r-a-y r-a-y said 1 year, 12 months ago:

    @jillsays – Here’s what you need to do:

    In your bbPress theme’s folder (/bb-templates/kakumei-blue), create a functions.php file and add the following:
    http://pastebin.com/PDeF3kjm (updated)

    You can adjust the default avatar in bbPress by going to the bbPress admin panel (/forum/bb-admin/) and clicking on “Settings > Discussion”.

    I’ve tried to “guess” where the BP avatar path is, however if this doesn’t work, you’ll have to adjust the $avatar_folder_dir variable manually (this will definitely apply to WPMU users).

    Give it a shot and report back.

  • Profile picture of jillsays jillsays said 1 year, 12 months ago:

    That’s great, @r-a-y! bbPress is now pulling in avatars for people who uploaded images through Buddypress.

    However, it is NOT pulling in images for people who only have a photo at Gravatar… and not one uploaded through Buddypress.

    Any way to tweak that?

  • Profile picture of r-a-y r-a-y said 1 year, 12 months ago:

    @jillsays – Did you read this:

    You can adjust the default avatar in bbPress by going to the bbPress admin panel (/forum/bb-admin/) and clicking on “Settings > Discussion”.