Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/10/2010 10:09:38 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Fixes #2288, #2183, and #2426.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-core/bp-core-avatars.php

    r3034 r3035  
    411411}
    412412
    413 // Override internal "get_avatar()" function to use our own where possible
     413/**
     414 * bp_core_fetch_avatar_filter()
     415 *
     416 * Attempts to filter get_avatar function and let BuddyPress have a go
     417 * at finding an avatar that may have been uploaded locally.
     418 *
     419 * @global array $authordata
     420 * @param string $avatar The result of get_avatar from before-filter
     421 * @param int|string|object $user A user ID, email address, or comment object
     422 * @param int $size Size of the avatar image (thumb/full)
     423 * @param string $default URL to a default image to use if no avatar is available
     424 * @param string $alt Alternate text to use in image tag. Defaults to blank
     425 * @return <type>
     426 */
    414427function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
    415     global $authordata;
    416 
     428
     429    // If passed an object, assume $user->user_id
    417430    if ( is_object( $user ) )
    418431        $id = $user->user_id;
     432
     433    // If passed a number, assume it was a $user_id
    419434    else if ( is_numeric( $user ) )
    420435        $id = $user;
    421     else
    422         $id = $authordata->ID;
    423 
     436
     437    // If passed a string and that string returns a user, get the $id
     438    else if ( is_string( $user ) && ( $user_by_email = get_user_by_email( $user ) ) )
     439        $id = $user_by_email->ID;
     440
     441    // If somehow $id hasn't been assigned, return the result of get_avatar
    424442    if ( empty( $id ) )
    425         return $avatar;
    426 
     443        return !empty( $avatar ) ? $avatar : $default;
     444
     445    // Let BuddyPress handle the fetching of the avatar
    427446    $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
    428447
     448    // If BuddyPress found an avatar, use it. If not, use the result of get_avatar
    429449    return ( !$bp_avatar ) ? $avatar : $bp_avatar;
    430450}
Note: See TracChangeset for help on using the changeset viewer.