#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.
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).