20 July 2010 2 Comments

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.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Live
  • Reddit
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz

2 Responses to “Buddypress avatars not shown in Cometchat after upgrade to WordPress 3.0”

  1. dz-tchat 24 August 2010 at 5:02 pm #

    hi, try to use bp_core_fetch_avatar

    bp_core_fetch_avatar( array(“item_id”=>$id,”type”=>”full”) );

    change the type of the returned image.

    can you send me your config.php i need the friendlist function function my email is gnawisoli@hotmail.com.

    thanks :) .

  2. hmm...? 13 October 2010 at 10:56 am #

    thanks


Leave a Reply