/** * Based on the * user_avatar_core_fetch_avatar_filter() 1.2.5 BP * * Description: Attempts to filter get_avatar function and let Word/BuddyPress have a go at * finding an avatar that may have been uploaded locally. * * @global array $authordata * @param string $avatar The result of get_avatar from before-filter * @param int|string|object $user A user ID, email address, or comment object * @param int $size Size of the avatar image (thumb/full) * @param string $default URL to a default image to use if no avatar is available * @param string $alt Alternate text to use in image tag. Defaults to blank * @return <type> */ function user_avatar_fetch_avatar_filter($avatar, $user, $size, $default, $alt) { global $pagenow; //If user is on discussion page, return $avatar if ($pagenow == "options-discussion.php") { return $avatar; } // If passed an object, assume $user->user_id if (is_object($user)) { $id = $user->user_id; } else { if (is_numeric($user)) { $id = $user; } else { if (is_string($user) && ($user_by_email = get_user_by_email($user))) { $id = $user_by_email->ID; } } } // If somehow $id hasn't been assigned, return the result of get_avatar if (empty($id)) { return !empty($avatar) ? $avatar : $default; } // Let us handle the fetching of the avatar $user_avatar = user_avatar_fetch_avatar(array('item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt)); // If we found an avatar, use it. If not, use the result of get_avatar $avatar_folder_dir = USER_AVATAR_UPLOAD_PATH . "{$id}/"; if (file_exists($avatar_folder_dir)) { return $user_avatar; } else { if (!file_exists($avatar_folder_dir)) { return $avatar; } } }
/** * user_avatar_get_avatar function. * * @access public * @param mixed $id * @param mixed $width * @return void */ function user_avatar_get_avatar($id, $width) { if (!get_option('show_avatars')) { if (user_avatar_avatar_exists($id)) { $user_avatar = user_avatar_fetch_avatar(array('item_id' => $id, 'width' => $width, 'height' => $width, 'alt' => '')); if ($user_avatar) { return $user_avatar; } else { return '<img src="' . USER_AVATAR_DEFAULT . '" width="' . $width . '" height="' . $width . '" class="avatar" />'; } } else { return '<img src="' . USER_AVATAR_DEFAULT . '" width="' . $width . '" height="' . $width . '" class="avatar" />'; } } else { return get_avatar($id, $width); } }