Skip to:
Content

BuddyPress.org

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#7056 closed defect (bug) (fixed)

When you disable gravatar and a loop calls the default local avatar, always calls the full size (even if you have requested the thumbnail size)

Reported by: r0z Owned by: boonebgorges
Milestone: 2.6 Priority: normal
Severity: normal Version:
Component: Media Keywords:
Cc:

Description

The bug can be reproduced in this way:

add in bp_custom.php:

/**
 * Disable gravatar, use instead local avatar (including default local avatar)
 */
add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

call the user avatar of a user without an avatar established, in content.php, single.php or wherever you want:

<?php echo get_avatar( $post->post_author, 50 ); ?>

or

<?php echo bp_core_fetch_avatar ( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ); ?>

Result:
we will get the default local avatar with the width and height attributes we requested in IMG tag, but the image itself is in full size, regardless of the size requested, in this case the thumb size.

We are expecting to:
get the thumb size of the default local avatar according to what we request.


This happens because when gravatar is disabled with this filter:

add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

the code responsible for executing this option:

buddypress\bp-core\bp-core-avatars.php
line 575

if ( ! apply_filters( 'bp_core_fetch_avatar_no_grav', $params['no_grav'], $params ) ) {
.
.
.
// No avatar was found, and we've been told not to use a gravatar.
} else {

	/**
	 * Filters the avatar default when Gravatar is not used.
	 *
	 * This is a variable filter dependent on the avatar type being requested.
	 *
	 * @since 1.5.0
	 *
	 * @param string $value  Default avatar for non-gravatar requests.
	 * @param array  $params Array of parameters for the avatar request.
	 */
	
	$gravatar = apply_filters( 'bp_core_default_avatar_' . $params['object'], bp_core_avatar_default( 'local' ), $params );
}

only takes into account this function to get the avatar :

line 663 (into $gravatar variable)

... bp_core_avatar_default( 'local' ) ...

and doesn't have a solution if a smaller size is required, such as 'thumb', which can be obtained with this other function:

bp_core_avatar_default_thumb( 'local' )

My not as good but temporary working solution (until the bug is fixed):

Replace this:

$gravatar = apply_filters( 'bp_core_default_avatar_' . $params['object'], bp_core_avatar_default( 'local' ), $params );

For this:

if ($params['width'] == BP_AVATAR_THUMB_WIDTH)
	$gravatar = apply_filters( 'bp_core_default_avatar_' . $params['object'], bp_core_avatar_default_thumb( 'local' ), $params );
else
	$gravatar = apply_filters( 'bp_core_default_avatar_' . $params['object'], bp_core_avatar_default( 'local' ), $params );

In this way, if we request an avatar in thumbnail size and you don't have one, we get the default local avatar in real thumbnail size.

PD: we cannot use the filter "bp_core_default_avatar_" to fix the bug in bp_custom.php, because the $params provided doesn't give us information about the required size.

Change History (5)

#1 @DJPaul
4 years ago

  • Milestone changed from 2.5.3 to Awaiting Review

#2 @boonebgorges
4 years ago

  • Keywords needs-patch removed
  • Milestone changed from Awaiting Review to 2.6

Hi @r0z - Thanks very much for the detailed report! This is a good catch - I'm surprised it hasn't been noticed before.

[10721] fixed this problem for group avatars (almost by accident).

#3 @boonebgorges
4 years ago

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

In 10754:

Default no_grav avatars should be thumb-sized when appropriate.

mystery-man-50.jpg should be served when:

  • A 'thumb' is requested, and the thumb width set in the config is 50 pixels or less, or
  • An avatar with a width of 50 or less is requested.

Props r0z.
Fixes #7056.

#4 @boonebgorges
4 years ago

In 10757:

After [10754], bp_get_user_has_avatar() should check against 'full' avatar.

bp_core_fetch_avatar() is now smarter about grabbing an appropriate-sized
avatar. See #7056. As such, the bp_core_fetch_avatar() check in
bp_get_user_has_avatar() should specify that the comparison will be against
a 'full' avatar, rather than the default 'thumb'.

#5 @DJPaul
4 years ago

  • Component changed from API - Avatars to Media
Note: See TracTickets for help on using tickets.