Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7424 closed defect (bug) (fixed)

filter get_avatar_url to parse URLs from BP avatars

Reported by: elhardoum's profile elhardoum Owned by: boonebgorges's profile boonebgorges
Milestone: 2.9 Priority: normal
Severity: normal Version:
Component: Extended Profile Keywords: has-patch commit
Cc:

Description

Hello,

This is my very first ticket and I hope I am not breaking something.

BuddyPress is [filtering](https://buddypress.trac.wordpress.org/browser/tags/2.7.4/src/bp-core/bp-core-avatars.php#L1466) [get_avatar()](https://developer.wordpress.org/reference/functions/get_avatar/) correctly to parse the custom avatars uploaded via member profile which is neat. However, it is not filtering [get_avatar_url()](https://developer.wordpress.org/reference/functions/get_avatar_url/) which is a WP function which basically used in most themes or plugins to get the avatar URLs easily rather than to decode the HTML output of get_avatar to get the image source attribute (src).

I hope this makes sense. Here's a paste of code for this filter http://pastebin.com/nQEEa7De

Thanks,
Samuel

Attachments (3)

bp_fetch_avatar_url_filter.php (1.6 KB) - added by elhardoum 7 years ago.
7424.01.patch (6.3 KB) - added by r-a-y 7 years ago.
7424.02.patch (6.4 KB) - added by r-a-y 7 years ago.

Download all attachments as: .zip

Change History (18)

#1 @DJPaul
7 years ago

  • Component changed from Core to Extended Profile
  • Milestone changed from Awaiting Review to 2.9

Thanks for the suggestion and your patch. This is a new function introduced very recently into WordPress, which is why we don't have historical support.

We'll look into this soon, but it probably won't make a BuddyPress shipping release for another 3-4 months (we're very near to releasing BuddyPress version 2.8, so it's unfortunate timing).

@r-a-y
7 years ago

#2 @r-a-y
7 years ago

01.patch deprecates the older bp_core_fetch_avatar_filter() function in favor for the added bp_core_get_avatar_data_filter() function.

bp_core_get_avatar_data_filter() hooks to the newer 'get_avatar_data' filter available since WordPress 4.2. The 'get_avatar_data' filter should also cover the 'get_avatar_url' filter.

The reason for deprecation is BP 2.9 supports a minimum of WP 4.4 and the 'get_avatar' filter is old. The get_avatar() function itself uses get_avatar_data().

Last edited 7 years ago by r-a-y (previous) (diff)

@r-a-y
7 years ago

#3 @r-a-y
7 years ago

01.patch filters 'get_avatar_data'.

02.patch filters 'get_avatar_url' instead. This might be more preferable since 'get_avatar_data' fires after the 'get_avatar_url' filter.

Last edited 7 years ago by r-a-y (previous) (diff)

#4 @hnla
7 years ago

@r-a-y This is a first patch ticket, is your update commit ready or should I apologize profusely to @elhardoum in having to punt this to 3.0 with the promise of an 'early' tag?

This ticket was mentioned in Slack in #buddypress by r-a-y. View the logs.


7 years ago

#6 @boonebgorges
7 years ago

  • Keywords commit added

Approach looks good to me.

#7 @boonebgorges
7 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 11614:

Filter WP avatars at get_avatar_url instead of get_avatar.

The get_avatar_url filter, introduced in WP 4.2, is a more general
point for filtering avatar URLs than the legacy get_avatar. The
URL-specific filter allows us to simplify our filter logic, and
ensures that developers fetching avatar data with get_avatar_data()
get BP avatars when appropriate.

Props elhardoum, r-a-y.
Fixes #7424.

#8 @hnla
7 years ago

Thanks @boone, @r-a-y and congrats @elhardoum your first ticket/patch is committed.

#9 @lne1030
7 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Type changed from enhancement to defect (bug)

Function bp_core_get_avatar_data_url_filter in the patch return null when the second param $id_or_email is an email address.

Here is the Code: [bp-core/bp-core-avatars.php#L1378](https://buddypress.trac.wordpress.org/browser/trunk/src/bp-core/bp-core-avatars.php#L1374)

Just add this code to line 1380 would fix this bug

} elseif (is_string( $id_or_email ))  {
  $user = get_user_by( 'email', $id_or_email );

#10 @r-a-y
7 years ago

In 11627:

Avatars: Add missing email condition in bp_core_get_avatar_data_url_filter()

Props lne1030.

See #7424.

#11 @r-a-y
7 years ago

In 11628:

Avatars: After r11627, switch from using is_string() to is_email()

See #7424.

#12 @r-a-y
7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Thanks for the report, @lne1030!

Just committed the fix.

#13 @r-a-y
7 years ago

In 11631:

Avatars: After r11627, ensure that $user is a WP_User object.

In bp_core_get_avatar_data_url_filter(), passing an email address that is
not a WP user would throw a notice.

See #7424.

#14 @r-a-y
7 years ago

In 11633:

Avatars: After r11627, move email check after user object checks.

Avoids notices from occurring.

See #7424.

#15 @r-a-y
7 years ago

In 11638:

Avatars: After r11627, fix notices appearing for anonymous commenters.

Props needle. See #7424.

Fixes #7568.

Note: See TracTickets for help on using tickets.