I am trying to replace WordPress comment author data:
1) Avatar (uploaded image instead of Gravatar)
2) Author link (link to author page as only members can comment)
I have found a great solution to this from this question, and have implemented the following code:
if ( ! function_exists( 't5_comment_uri_to_author_archive' ) )
{
add_filter( 'get_comment_author_url', 't5_comment_uri_to_author_archive' );
function t5_comment_uri_to_author_archive( $uri )
{
global $comment;
// We do not get the real comment with this filter.
if ( empty ( $comment )
or ! is_object( $comment )
or empty ( $comment->comment_author_email )
or ! $user = get_user_by( 'email', $comment->comment_author_email )
)
{
return $uri;
}
return get_author_posts_url( $user->ID );
}
}
The code works perfect for replacing links, and I want to use it to replace the avatars as well. I have created a copy of the function, and changed the names and the return:
if ( ! function_exists( 'my_comment_imgs' ) )
{
add_filter( 'get_comment_author_url', 'my_comment_imgs' );
function my_comment_imgs( $uri )
{
global $comment;
// We do not get the real comment with this filter.
if ( empty ( $comment )
or ! is_object( $comment )
or empty ( $comment->comment_author_email )
or ! $user = get_user_by( 'email', $comment->comment_author_email )
)
{
return $uri;
}
return get_avatar( $user->ID );
}
}
However, this function negates the first one, so I get updated avatars, but loose the author links. How do I replace both elements at the same time (avatars and links)?