Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use this micro message system script and I want to add an avatar to it, however, my lack of PHP knowledge is making this difficult.

The code I use to display an avatar is:

userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '')

And I want to inject this avatar to this part of the message script (inside a loop):

$r = $r . '<tr id="wpam-reply-' . $post->post_ID . '-' . $count . '" ' . $style . '>';
$r = $r . '<td style="padding:10px 0 10px 10px; width:40px;"><span title="' . $user_info->display_name . ' (' . $user_info->user_login . ')">' . userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '') . '</span></td>';
$r = $r . '<td>' . wpam_get_message($reply, $user_info, $options, 2) . '</td>';
$r = $r . '</tr>';

If you look at the second line, you will see how I added it there. However, this does not return the avatar where it should be. It appears outside everything else. Maybe because it returns a string rather than data? I am not sure as I am only just familiarising myself with PHP terminology.

EDIT: Just to clarify, on the HTML output, the avatar images appear outside of the table, when they should be inside the <td style="padding:10px 0 10px 10px; width:40px;"> tag.

EDIT 2: Someone pointed out that `userphoto_thumbnails prints out the image, while I am trying to concatenate it. Its being printed out when I'm creating the string, so it's appearing in the wrong place. So I tested:

echo '<tr id="wpam-reply-' . $post->post_ID . '-' . $count . '" ' . $style . '>';
echo '<td style="padding:10px 0 10px 10px; width:40px;"><span title="' . $user_info->display_name . ' (' . $user_info->user_login . ')">' . userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '') . '</span></td>';
echo '<td>' . wpam_get_message($reply, $user_info, $options, 2) . '</td>';
echo '</tr>';

But this did not work either. I am certain that I have not added the avatar code to the script correctly, can you assist?

share|improve this question
    
please also post the full code of the function userphoto_thumbnail() - for your purpose, this needs to return the avatar instead of printing it –  Michael Sep 10 '12 at 16:22
    
@Michael userphoto is a plugin, according to its documentation: wordpress.org/extend/plugins/user-photo it prints out the image. How can I solve this issue without changing the core script of userphoto (if possible)? –  Amanda Bynes Sep 10 '12 at 16:27
add comment

1 Answer

There is a native WordPress function to do exactly what it sounds like you're trying to do.

You need to replace

userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '')

with

get_avatar($user_info->ID,40)

Check here for your future reference - http://codex.wordpress.org/Function_Reference/get_avatar

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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