[buddypress-trac] [BuddyPress Trac] #7056: 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)

buddypress-trac noreply at wordpress.org
Sat May 7 15:32:13 UTC 2016


#7056: 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)
---------------------------+-------------------------
 Reporter:  r0z            |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  2.5.3
Component:  API - Avatars  |    Version:
 Severity:  normal         |   Keywords:  needs-patch
---------------------------+-------------------------
 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.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7056>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list