in PHP, Wordpress

Buddypress avatars not shown in Cometchat after upgrade to WordPress 3.0

I was having problems showing the Buddypress avatars in Cometchat after upgrading to version 3.0 of WordPress. Instead of showing the Buddypress avatars, Cometchat was showing a Gravatar.

Looks like the problem is that WordPress 3.0 has a different directory structure and Cometchat can’t locate the files anymore.

To solve this I had to change the getAvatar function in cometchat/config.php file:

function getAvatar($data) {
 
	$data = explode('|',$data);
	$id = $data[0];
	$blog = 1;
 
	if (is_dir((dirname(dirname(__FILE__)).'/wp-content/blogs.dir/' . $blog . '/files/avatars/' . $id))) {
		$files = "";
		if ($handle = opendir(dirname(dirname(__FILE__)).'/wp-content/blogs.dir/' . $blog . '/files/avatars/' . $id)) {
			while (false !== ($file = readdir($handle))) {
				if ($file != "." && $file != "..") {
					if(substr($file, -11, 7) == "bpthumb" ) {
						$files .= $file;
					}
				}
			}
			closedir($handle);
		}
 
		if (file_exists((dirname(dirname(__FILE__)).'/wp-content/blogs.dir/' . $blog . '/files/avatars/' . $id . '/' . $files))) {
			return '/files/avatars/' . $id . '/' . $files;
		}
	}
	return 'http://www.gravatar.com/avatar/'.md5($data[1]).'?d=wavatar&s=80';
}

The $blog should be the id of your blog/site showing Cometchat. If you have multiple sites in a single WordPress installation showing Cometchat, you may need to make some changes here to make this variable dynamic.