buddypress Tag Archive

Enabling Twitter avatars within BuddyPress

First up, the first step in this process is to install the Twit Connect plugin which you can do by following these instructions, then you can proceed with enabling Twitter avatars.

First up, the first step in this process is to install the Twit Connect plugin which you can do by following these instructions, then you can proceed with enabling Twitter avatars.

This is just a quick filter that I wrote while I was setting up help.deanjrobinson.com last week after I discovered that the twitter avatars weren’t working because of a different function/filter being used by BuddyPress.

I make no claims that this additional function is perfect, but I haven’t come across any problems with it yet, and I only knocked it together quickly. If you find anything wrong with it, or have any suggestions as to how it could be improved/simplified please let me know.

This new function based on one of the original functions that comes with the Twit Connect plugin which enables twitter avatars on regular WordPress blogs, just a with a few tweaks.

What you need to do is add the following code to the functions.php in your current BuddyPress theme. You can download a plain text copy of this function here (it’ll probably more reliable than copy-and-pasting from this page). Remember to backup your functions.php file before making any changes… just in case.

UPDATE: Appears some people who added this function the functions.php file in the default BuddyPress theme were seeing some error messages (I have not yet been able to recreate this error, but more than one user has reported it). Ideally you shouldn’t be modifying the default BP theme directly, you should be doing it via a child theme (find out how), so this code should be then added to the functions.php in your child theme.

7th March, UPDATE I’ve updated the function below (and the downloadable version above) to use http://tweetimag.es for the static twitter avatar URLs, it looks like it might a more reliable/consistent service.

<?php

 function bp_twc_get_avatar($avatar, $id_or_email='') {
  global $comment, $twc_user_login_suffix;

  if(is_object($comment)) {
   $user_id = $comment->user_id;
  }

  if (is_object($id_or_email)) {
   $user_id = $id_or_email->user_id;
  }

  if (is_array($id_or_email)) {
   if ($id_or_email['object']=='user') {
    $user_id = $id_or_email['item_id'];
   }
  }

  if (get_usermeta($user_id, 'twcid')) {
   $user_info = get_userdata($user_id);
   $twav_suffix = '';

   if ( $id_or_email['width'] ) {
    $twav_size = $id_or_email['width'];
    if( $twav_size < 32 ) {
     $twav_suffix = 'm';
    } else if ( $twav_suffix < 64 ) {
     $twav_suffix = 'n';
    } else {
     $twav_suffix = 'b';
    }
   } else if ( 'full' == $id_or_email['type'] ) {
    $twav_size = BP_AVATAR_FULL_WIDTH;
    $twav_suffix = 'b';
   } else if ( 'thumb' == $id_or_email['type'] ) {
    $twav_size = BP_AVATAR_THUMB_WIDTH;
    $twav_suffix = 'n';
   }

   $out = 'http://img.tweetimag.es/i/'. str_replace($twc_user_login_suffix,"",$user_info->user_login) . '_' .$twav_suffix;

   $avatar = "<img alt='Twitter Avatar' src='{$out}' class='avatar avatar-{$twav_size}' height='{$twav_size}' width='{$twav_size}' />";
   return $avatar;

  } else {
   return $avatar;
  }

 }

 // Check if Twit Connect exists (since its without it this function is pointless)
 if( function_exists( 'twit_connect' ) ) {

  add_filter( 'bp_core_fetch_avatar', 'bp_twc_get_avatar',10,4);

 }

?>

Show me the original version

I will add an explanation of what its doing if people are interested/curious.

·•·

Want Help? Come get some!

I’ve grown tired of doing support via blog comments or emails, so it’s time for a change. Introducing HELP! my new BuddyPress powered support site. You can now get support for all my WordPress plugins and themes, plus Hahlo, nextga.me (once its finished.…) and other projects all in one spot.

I’ve grown tired of doing support via blog comments or emails, so it’s time for a change. Introducing HELP! my new BuddyPress powered support site. You can now get support for all my WordPress plugins and themes, plus Hahlo, nextga.me (once its finished.…) and other projects all in one spot.

Want Help? Come get some!

In the past I’ve had trouble finding a “good” solution for support. I’ve tried various forum packages, with each being abandoned because they were either insufficient or superfluous to my needs… that and every forum I’ve run has been hit by low-life spammers selling v1agr4 or offering to transfer $99,000,000,000 to me from their Nigerian bank account.

Following these ‘failures’ I tried hosted solutions like GetSatisfaction and UserVoice, again they didn’t really meet my needs, and I found that I was still left fielding support questions in blog comments and via email. In the case of support for Hahlo I stuck pretty strongly to GetSatisfaction (even if I didn’t check it as often as I probably should have). Recently GetSatisfaction have announced changes to their pricing plans, which ultimately means the free account (which I’ve been using) would appear that its losing a bunch of the more useful features. I should clarify that this change isn’t the only reason I’m moving away from GetSatisfaction, the main reason is that I wanted something I had more control over, and that I could also use for supporting my WordPress Plugins and Themes etc.

» Continue reading “Want Help? Come get some!”

Article 24 Feb 2010 3 comments
·•·
twitter was not updated. | lastfm was not updated. |