Replace comment avatars and links at the same time

Maybe I was burned out from work before, but this morning I took another go at the same code and managed to get it running properly.

if ( ! function_exists( 'comment_imgs' ) )
{
add_filter( 'get_comment_author_url', 'comment_imgs' );

function comment_imgs( $avatar, $id_or_email, $size, $default, $alt )
{
    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 );
}
}

Credit for the original code goes to Thomas Scholz for linking to author pages, this modification retrieves local avatars and two functions don’t clash with each other.