1

I am using the UserPhoto plugin which allows users to upload a photo which can be used in many ways. (It's awesome) But I would also like when the admins look at the list of users the column displays this users photo instead of the Gravatar. Is there a hook?

I'm a little closer...

function change_user_avatar_col( $column ) {
    $column['avatar'] = 'avatar';

    return $column;
}
add_filter( 'manage_users_columns', 'change_user_avatar_col' );

function change_user_avatar( $val, $column_name, $user_id ) {
    $user = get_userdata( $user_id );

    switch ($column_name) {
        case 'avatar' :
            return userphoto_thumbnail($user);
            break;

        default:
    }
    return $return;
} 
add_filter( 'manage_users_custom_column', 'change_user_avatar', 10, 3 );

I am getting the images but they they are not in the column, plus I really want to replace the current gravatars and this is creating an additional column. I tried changing out the "avatar" to "Username" for the column but no success.

1

Not tested, but much probably this works:

Instead of trying to add/change the columns, change the get_avatar behavior.

For one, it is a pluggable function, so it can be overridden. And second, there are many Questions in this Stack on how to modify/customize the avatars.

Check this two:

In the first one, Bainternet states:

But the better part of User Photo plugin is that it has an overwrite function get_avatar which will get the user photo if exists or the gravatar if not.

-2

ok i solved this problem through hacking around

in the wp-admin/includes/class-wp-users-list-table.php

i eddited on line 285, the: case 'username' as followed

                  case 'username':                      
                    $user = get_userdata( $user_object->ID, 32);  
                    if (userphoto_exists($user)){ // set the userphoto picture as avatar > must be .jpg
                        $theImageUrl = "http://YOUR_WEBSITE/wp-content/uploads/userphoto/$user->ID.jpg";
                        $r .= "<td $attributes> <img src='$theImageUrl' width='32' height='32'/> $edit</td>";
                    }
                    else // if there is no user photo, set default avatar
                    {
                        $avatar = get_avatar($user->ID, 32);
                        $r .= "<td $attributes>$avatar $edit</td>";
                    } 
                    break;

note: user_photo pictures must be in .jpg.

my help-source for this was user > dikkevandale on > http://wordpress.org/support/topic/plugin-user-photo-how-do-i-return-just-the-image-url

thx! dimi

  • Dimi you used "hacking around" and I would consider this a hack. I was hoping to find a hook as to not touch the core. Thanks though. – Gregg Franklin Nov 7 '11 at 17:51
  • 1
    Hacking the core is not considered a good answer in this Stack. Also, you are hardcoding the wp_upload_dir. – brasofilo Jun 30 '12 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.