What you need to use here is the WP_Comment_Query() function.
So on the author.php
page, you can easily get the author info and ID as followed:
// get author info
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
// set ID
$user_id = $curauth->ID;
Then we add the user ID in the query arguments array:
$args = array(
'user_id' => $user_id, // comments by this user only
'status' => 'approve',
'post_status' => 'publish',
'post_type' => 'post'
);
And finally we hit the arguments in the wp_comment_query()
:
// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
// Comment Loop
if ( $comments ) {
foreach ( $comments as $comment ) {
echo '<p>' . $comment->comment_content . '</p>';
}
} else {
echo 'No comments found.';
}
As an added bonus, I investigated how pagination works with wp_comment_query()
for not long ago and offer a good solution here. It was a little bit of a fiddle-niddle to make it work.
EDIT:
A better way to get the author ID is simply with (props @Pieter):
$user_id = get_queried_object_id();