Skip to:
Content

BuddyPress.org

Changeset 7769


Ignore:
Timestamp:
02/02/2014 07:09:47 PM (11 years ago)
Author:
boonebgorges
Message:

Improve default avatar handling in bp_core_fetch_avatar()

Changes to Gravatar over the last few years have placed restrictions on the way
that a default gravatar (to be used as a fallback for when no actual Gravatar
is found) can be served to gravatar.com. In particular, Gravatar cannot cache
and serve default images that are not publicly available (as in dev
environments) or are only available over SSL.

Because BuddyPress's default behavior was to provide a local copy of the
mystery-man avatar, switching to Gravatar's hosted mystery-man solves these
problems for sites that are using the default mystery-man as a fallback image.

This changeset also reconfigures the way that the BP_AVATAR_DEFAULT constant
is respected, to ensure that it's possible to override the avatar fallback when
no_grav is set to true.

Fixes #4571

Props r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-avatars.php

    r7756 r7769  
    3838        }
    3939    }
    40 
    41     if ( !defined( 'BP_AVATAR_DEFAULT' ) )
    42         define( 'BP_AVATAR_DEFAULT', $bp->plugin_url . 'bp-core/images/mystery-man.jpg' );
    43 
    44     if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
    45         define( 'BP_AVATAR_DEFAULT_THUMB', $bp->plugin_url . 'bp-core/images/mystery-man-50.jpg' );
    4640
    4741    if ( ! defined( 'BP_SHOW_AVATARS' ) ) {
     
    7468
    7569    // Defaults
    76     $bp->avatar->thumb->default = BP_AVATAR_DEFAULT_THUMB;
    77     $bp->avatar->full->default  = BP_AVATAR_DEFAULT;
     70    $bp->avatar->thumb->default = bp_core_avatar_default_thumb();
     71    $bp->avatar->full->default  = bp_core_avatar_default();
    7872
    7973    // These have to be set on page load in order to avoid infinite filter loops at runtime
     
    440434            $default_grav = 'wavatar';
    441435        } else if ( 'mystery' == $bp->grav_default->{$object} ) {
    442             $default_grav = apply_filters( 'bp_core_mysteryman_src', bp_core_avatar_default(), $grav_size );
     436            $default_grav = apply_filters( 'bp_core_mysteryman_src', 'mm', $grav_size );
    443437        } else {
    444438            $default_grav = $bp->grav_default->{$object};
     
    472466    // No avatar was found, and we've been told not to use a gravatar.
    473467    } else {
    474         $gravatar = apply_filters( "bp_core_default_avatar_$object", $bp->plugin_url . 'bp-core/images/mystery-man.jpg', $params );
     468        $gravatar = apply_filters( "bp_core_default_avatar_$object", bp_core_avatar_default( 'local' ), $params );
    475469    }
    476470
     
    11171111 * @since BuddyPress (1.5.0)
    11181112 *
     1113 * @param string $type 'local' if the fallback should be the locally-hosted
     1114 *        version of the mystery-man, 'gravatar' if the fallback should be
     1115 *        Gravatar's version. Default: 'gravatar'.
    11191116 * @return string The URL of the default avatar.
    11201117 */
    1121 function bp_core_avatar_default() {
    1122     return apply_filters( 'bp_core_avatar_default', buddypress()->avatar->full->default );
     1118function bp_core_avatar_default( $type = 'gravatar' ) {
     1119    // Local override
     1120    if ( defined( 'BP_AVATAR_DEFAULT' ) ) {
     1121        $avatar = BP_AVATAR_DEFAULT;
     1122
     1123    // Use the local default image
     1124    } else if ( 'local' === $type ) {
     1125        $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man.jpg';
     1126
     1127    // Use Gravatar's mystery man as fallback
     1128    } else {
     1129        if ( is_ssl() ) {
     1130            $host = 'https://secure.gravatar.com';
     1131        } else {
     1132            $host = 'http://www.gravatar.com';
     1133        }
     1134
     1135        $avatar = $host . '/avatar/00000000000000000000000000000000?d=mm&s=' . bp_core_avatar_full_width();
     1136    }
     1137
     1138    return apply_filters( 'bp_core_avatar_default', $avatar );
    11231139}
    11241140
     
    11261142 * Get the URL of the 'thumb' default avatar.
    11271143 *
     1144 * Uses Gravatar's mystery-man avatar, unless BP_AVATAR_DEFAULT_THUMB has been
     1145 * defined.
     1146 *
    11281147 * @since BuddyPress (1.5.0)
    11291148 *
     1149 * @param string $type 'local' if the fallback should be the locally-hosted
     1150 *        version of the mystery-man, 'gravatar' if the fallback should be
     1151 *        Gravatar's version. Default: 'gravatar'.
    11301152 * @return string The URL of the default avatar thumb.
    11311153 */
    1132 function bp_core_avatar_default_thumb() {
    1133     return apply_filters( 'bp_core_avatar_thumb', buddypress()->avatar->thumb->default );
    1134 }
     1154function bp_core_avatar_default_thumb( $type = 'gravatar' ) {
     1155    // Local override
     1156    if ( defined( 'BP_AVATAR_DEFAULT_THUMB' ) ) {
     1157        $avatar = BP_AVATAR_DEFAULT_THUMB;
     1158
     1159    // Use the local default image
     1160    } else if ( 'local' === $type ) {
     1161        $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man-50.jpg';
     1162
     1163    // Use Gravatar's mystery man as fallback
     1164    } else {
     1165        if ( is_ssl() ) {
     1166            $host = 'https://secure.gravatar.com';
     1167        } else {
     1168            $host = 'http://www.gravatar.com';
     1169        }
     1170
     1171        $avatar = $host . '/avatar/00000000000000000000000000000000?d=mm&s=' . bp_core_avatar_thumb_width();
     1172    }
     1173
     1174    return apply_filters( 'bp_core_avatar_thumb', $avatar );
     1175}
Note: See TracChangeset for help on using the changeset viewer.