I need user_picture, but I want to use a picture from profile2 image field to be that picture.

My users can upload several pictures of themselves. I would like the first image to be the "user_picture" for PM, Author Pane, and so on. And if they reorder their pictures whichever one they make the lightest weight will be their new "user_picture".

Currently my users have to manage their user_picture from their account page and manage their Profile2 images from their profile2 profile page. This is a pain and it sometimes means my users have to upload the same picture twice if they want it as their user_picture AND displayed in their profile. So, basically I want all images managed in the user's profile2 profile and not use the "up load user picture" in their account settings page.

This code seems to be what I need, but I can't figure out where to put the code. I know I need to build this to work with 'privatemsg-view.tpl.php' with <?php //print $picture ?> <?php echo $user_image ?> But where does the code below go?

$user_image=''; 
  //loading 'profile2' information 
  $profile=profile2_load_by_user($comment->uid,'personal_info'); 
    if(is_object($profile)){ 
    //Showing 'profile2' image field picture instead of drupal default user image
    if(is_array($profile->field_profile_image)&& count($profile->field_profile_image)>0){
  $file_url=$profile->field_profile_image['und'][0]['uri']; 
  //Applying image style to that image $user_image=theme('image_style', array('style_name' => 'comment_form_user_image', 'path' =>$file_url)); 
}else{ 
//if user doesn't upload any profile picture in profile2 form and then show default $user_image=''; }
}else{ 
//if user doesn't upload any profile information and then show default $user_image=''; }

Comments

VM’s picture

System Lord’s picture

I agree with wwwjaylee. D7 already does this for user. (see: https://www.drupal.org/node/1985004#comment-9434381)

I'm using Profile2 and need to use Profile2 image fields not Durpal's default user account field.

Thanks, tho!

System Lord’s picture

I stand corrected! I looked into this mod a month ago and couldn't get it to work. After your post I thought I would try it again. Now it works! For anyone in the same situation it's important (after install) to resave the user profile and flush cache.

Thanks VM