Guest User

r-a-y

a guest
May 25th, 2010
1,303
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function bb_bp_avatar($avatar, $id_or_email, $size, $default, $alt) {
  3.  
  4.     $class = 'photo avatar avatar-'. $size;
  5.  
  6.     $author_id = get_post_author_id();
  7.  
  8.     $avatar_folder_url = '/wp-content/uploads/avatars/'. $author_id;
  9.  
  10.     $avatar_folder_dir = $_SERVER['DOCUMENT_ROOT'] . $avatar_folder_url;
  11.    
  12.     $avatar_name = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
  13.     $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
  14.    
  15.     if ( file_exists( $avatar_folder_dir ) ) {
  16.         if ( $av_dir = opendir( $avatar_folder_dir ) ) {
  17.             while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
  18.                 if ( preg_match( "/{$avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_user_avatar_name}/", $avatar_file ) )
  19.                     $avatar_url = $avatar_folder_url . '/' . $avatar_file;
  20.             }
  21.         }
  22.         closedir($av_dir);
  23.  
  24.         if ( $avatar_url )
  25.             return "<img src='{$avatar_url}' alt='{$alt}' class='{$class}' width='{$size}' height='{$size}' />";
  26.     }
  27.  
  28.     return $avatar;
  29. }
  30. add_filter( 'bb_get_avatar', 'bb_bp_avatar', 1, 5 );
  31. ?>
RAW Paste Data