Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

edow on "get_avatar shows the same avatar for all users"

$
0
0

I have the following code to show the user avatars in the comment section:
<img src=\"".get_avatar_url(get_avatar( $comment->comment_author_email, 50 ))."\" class=\"tooltip\" title=\"$like->comment_author\">

My functions file contains this code so it returns the avatar url only:

function get_avatar_url($get_avatar){
    preg_match("/src='(.*?)'/i", $get_avatar, $matches);
    return $matches[1];
}

I use the plugin https://wordpress.org/plugins/simple-local-avatars/ to upload a custom avatar.

The plugin is working great, but with the above code every user avatar in the comment section shows the same avatar instead of their own avatar. If I look in the admin section the avatars showing the right avatar for each user.

Can anyone help me with this. I can't find out what I'm doing wrong.

Even <?php echo get_avatar( $id_or_email, $size, $default, $alt ); ?> isn't working.

This is the rest of the code which shows the comments:

<div class="post-comments">
			<div class="upvoters" id="votes">
			<?php $comments = get_comments( array('post_id' => get_the_ID(),) );
			$likes = array();
			$unlikes = array();
			foreach( $comments as $comment ) {
				if('unlike' == $comment->comment_content ) $unlikes[] = $comment;
					else $likes[] = $comment;
			}
			echo '<h3>'.count($likes).' bezoekers vinden dit leuk</h3>';
			echo '<div class="upvoter-img">';
			foreach( $likes as $like )
				echo("<img src=\"".get_avatar_url(get_avatar( $comment->comment_author_email, 50 ))."\" class=\"tooltip\" title=\"$like->comment_author\">");
			echo '</div>';
			?>
			</div>

			<div class="downvoters">
			<?php
			echo '<h3>'.count($unlikes).' bezoekers vinden dit niet leuk</h3>';
			echo '<div class="downvoter-img">';
			foreach( $unlikes as $unlike )
				echo("<img src=\"".get_avatar_url(get_avatar( $comment->comment_author_email, 50 ))."\" class=\"tooltip\" title=\"$unlike->comment_author\">");
			echo '</div>';
			?>
			</div>

			<div class="clearBoth"></div>
		</div>

Hopefully anyone can help me out.


Viewing all articles
Browse latest Browse all 8245

Trending Articles