#6440 closed defect (bug) (no action required)
BP Displayed User Avatar Bug
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | critical | Version: | 2.2.3 |
Component: | Media | Keywords: | reporter-feedback |
Cc: |
Description
I discussed this on the Slack channel a few days ago and after more testing, I believe I found a bug.
This must be related to #6290 and #6278.
Steps to reproduce:
1 - Add an avatar using the new Avatar UI (which as far as I understand, uses the new Attachments API);
2 - Use the bp_core_fetch_avatar()
to fetch an avatar anywhere outside of the main loop. Like in the header of a theme;
3 - Go the User profile, bp_displayed_user_avatar()
on the profile-header.php will show new added avatar and also bp_core_fetch_avatar()
will show the new user avatar on the user profile pages;
My thinking after looking at the code, they appear normal because they both use bp_displayed_user_id()
to fetch the current logged-in user.
4 - Now go to another page that's not related to BuddyPress (custom post type, post type pages, aka blog post in my case) and bp_core_fetch_avatar()
will not fetch the new uploaded image, it'll fetch a gravatar image if available or a mystery man if not.
In another words, outside of the BuddyPress domain, bp_core_fetch_avatar()
is not fetching the new uploaded avatar.
I wasn't smart enough to know why, but after a few tests, that's what I came up with to show the image on non-BuddyPress pages as well as BuddyPress pages.
bp_displayed_user_avatar ( array( 'item_id' => get_current_user_id() ) );
Using the WordPress function to fetch the current user, instead of the BuddyPress one solved for me. It showed the newly added avatar, if not they fetched the gravatar version and if that wasn't available either, it fetched the mystery man finally.
Change History (4)
#1
@
10 years ago
- Milestone changed from Awaiting Review to 2.3
- Severity changed from normal to critical
#2
@
10 years ago
- Keywords reporter-feedback added; needs-patch removed
Hi @espellcaste
Maybe i'm missing something, but I believe there's no issue at all, because out of the single member's pages, bp_displayed_user_id()
is 0
so bp_core_fetch_avatar()
if no item_id
parameter was provided should display nothing (see https://buddypress.trac.wordpress.org/browser/trunk/src/bp-core/bp-core-avatars.php#L245).
But as you were talking of the BP Attachments API and the new avatar UI, i've double checked. This is what i've did, i've switched to 2.2 branch, follow the different steps you detailed in you ticket description. And the only way to have an avatar displayed in the header of the theme, is to actually set the displayed user id by going on one of the single member's pages.
I've switch back to trunk, follow the different steps again, by uploading a new avatar or using the camera feature, and the result is the same than in 2.2, no avatar displayed if not on a single member's page, which is the right behavior.
So no regression.
My thinking after looking at the code, they appear normal because they both use bp_displayed_user_id() to fetch the current logged-in user.
No to fetch the logged in user id, you need to use bp_loggedin_user_id()
. Displayed user means, the one you're actually looking at : so a single member's page. bp_core_fetch_avatar()
tries to get the displayed user id if no item_id was provided, if the item_id is still empty, then it returns nothing.
4 - Now go to another page that's not related to BuddyPress (custom post type, post type pages, aka blog post in my case) and bp_core_fetch_avatar() will not fetch the new uploaded image, it'll fetch a gravatar image if available or a mystery man if not.
In another words, outside of the BuddyPress domain, bp_core_fetch_avatar() is not fetching the new uploaded avatar.
I really wonder how you managed to have an avatar displayed in this case, nothing should be output!
Do you have any plugin activated or do you use a specific theme, if so could, you deactivate all plugins except BuddyPress and test with a twenty of your choice, e.g. twentyfifteen.
If not on a single member's page, you need to pass an item_id parameter to bp_core_fetch_avatar()
. For instance :
<?php echo bp_core_fetch_avatar( array( 'item_id' => 43 ) ); ?>
or if you're trying to fetch the current logged in user's avatar, you can use
<?php bp_loggedin_user_avatar(); ?>
So for me, there's no bug. If i've missed something, do not hesitate to share the exact code you're using and the exact config.
#3
@
10 years ago
- Milestone 2.3 deleted
- Resolution set to invalid
- Status changed from new to closed
Hi @imath, thanks for looking at it.
In fact, there isn't a bug. My reasoning was wrong and I'm afraid you are correct.
I think I didn't quite understand the main purpose of the bp_core_fetch_avatar()
function and after you explanation, I fully understood it.
Also after a few tests here, the bp_core_fetch_avatar()
didn't return an image until I changed the item_id to bp_loggedin_user_id()
which in this situation, should work as expected and as you explain in your answer. Honestly, now I'm not sure how I got like I said, I think after so many attempts of fixing it, I got confused and mistakenly said that.
Overall, the function that I needed and was the one which solved the problem was bp_loggedin_user_avatar()
. As I wanna an user avatar, I didn't look in the Members component in BuddyPress, I was straight to bp-core-avatar.php.
Thanks anyway!
Flagging this so that imath will be able to take a look, in case this is a regression for 2.3.