Cannot get local avatars to show

See updates below. I upgraded to 3.7.1 using svn. I did this on my localhost first to make sure everything is fine. Everything was, so I proceeded to do it on the server. However, on the server, the users’ avatars are not showing up and instead everyone is getting Gravatar’s mystery man.

Here is the code I have in my functions.php:

Read More
<?php switch ( $comment->comment_type ) :
case '' :
?>
<p <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<?php echo get_avatar( $comment, 40 ); ?>

When I look at the source of the generated page on my localhost for the above I get the following code:

<img src="http://localhost/[path]/wp-content/uploads/avatars/[a number]/[imagename.jpg]"

On the server when I view source I get the following code for the same user:

<img src="http://gravatar.com/avatar/[alphanumeric]=http://[mywebsite.com]/wp-content/plugins/buddypress/bp-core/images/mystery-man.jpg[code]"

I must be making a mistake somewhere but for the life of me I cannot figure it out. The only explanation I can come up with is that Gravatar is not accepting requests from localhost and that is why it is working the way I would like it to on my localhost.

So what do I have to do to make their local avatars show up (the ones they uploaded themselves)? I should also add that I am using the BuddyPress plugin (both on localhost and server).

Aside from that, is there a technique people use to compare the files on the server with those on the development machine? Something akin to vimdiff?

UPDATE: I copied the localhost directory recursively using cp -r to another directory. I then rsynced that directory with the remote server making it a mirror of the server. Then I ran diff -NbBiwr /path/to/localhost /path/to/localhostCopyThatWasRsynced and received no major differences save for stuff in the .svn directories. When I view the copied version in a browser the local avatars show up. This is really starting to make no sense at all. I also updated the sql database to reflect the one on the remote server and the local avatars show up on localhost but not on the remote server.

UPDATE 2: Here are all the things I attempted since the last update:

  1. Toggle wp-debug to true. No errors of note.
  2. Removed the entire directory, did a new svn co.
  3. Deactived all other plugins besides BuddyPress.
  4. Used the default BuddyPress theme.
  5. Installed version 3.6.1 (the last good version I used).
  6. Checked and rechecked directory permissions.
  7. I removed the avatars directory and when someone tries to upload an avatar it creates the avatars directory and the userid subdirectory but the image does not upload. The subdirectory remains blank. This is the error that is returned on the front end Upload Failed! Error was: Unable to create directory wp-content/uploads/avatars/1407/avatars/1407. Is its parent directory writable by the server? As you can see it duplicates the avatars directory and the userid subdirectory for some reason. This happens on both the server and localhost. Localhost is displaying avatars properly however.
  8. Tinkered with birgire’s suggestions below. Nothing.

Related posts

2 comments

  1. Debug ideas:

    You could try to see if this has any effect:

    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    

    But you should check out the parameters that go through the bp_core_fetch_avatar filter to see if they are correct (untested):

    add_filter( 'bp_core_fetch_avatar', 'my_bp_core_fetch_avatar', 99, 9 );
    
    function my_bp_core_fetch_avatar( $html, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir )
    {
        // debug:
        $args = array( 
                        'html'              => $html,
                        'params'            => join( ', ', $params ),
                        'item_id'           => $item_id,
                        'avatar_dir'        => $avatar_dir,
                        'css_id'            => $css_id,
                        'html_width'        => $html_width,
                        'html_height'       => $html_height,
                        'avatar_folder_url' => $avatar_folder_url,
                        'avatar_folder_dir' => $avatar_folder_dir,
                );
    
       $debug = date_i18n( 'c' );
    
       foreach( $args as $key => $value )
       {
           $debug .= sprintf( ' | %s: %s ', $key, $value );
       } 
    
        error_log( $debug . PHP_EOL , 3, '/path/to/my/debug.log' ); 
    
        return $html;
    }
    

    where you have to modify the path to your writeable debug.log file.

    The file should then contain lines like this one:

    2013-11-12T12:01:16+00:00 | html: ???  | params: ???  | item_id:  ??? | avatar_dir: ??? | css_id: ??? | html_width: ??? | html_height: ??? | avatar_folder_url: ??? | avatar_folder_dir: ???
    

    I updated the above debug code, to take into account that $params is an array.

    Some general remarks:

    It’s interesting to look into the file /bp-core/bp-core-avatars.php.

    The avatar image seems to be overwritten via this filter:

    add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
    

    and inside the bp_core_fetch_avatar_filter() callback you have this line:

     // Let BuddyPress handle the fetching of the avatar
    $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
    

    and it was inside that function, I found the applied bp_core_fetch_avatar filter.

    So I think these functions might be worth debugging further or maybe you could try to correct the avatars via the above bp_core_fetch_avatar filter?

  2. It turns out there was something wrong with the uploads folder. If anybody has this issue in the future, this is what to do.

    1. Deactivate BuddyPress.
    2. chmod 777 uploads/
    3. Reinstall BuddyPress
    4. chmod 775 uploads/

    That was all it was.

Comments are closed.