You can use get_comments()
function to retrieve comments by user_id
or you can modify the below to also accept author_email
or multiple authors. It will then only return the Comment IDs as an array and count them up, returning the integer which could be 0.
/**
* Count and return number of comments by User ID
*
* @param Integer $user_id - User ID of the wanted user
*
* @return Integer - Number of comments by given user
*/
function wpse284435_comment_count_by_author( $user_id ) {
$user_id = ( ! empty( $user_id ) ) ? intval( $user_id ) : get_current_user_id();
$comments = get_comments( array(
'fields' => 'ids',
'user_id' => $user_id,
) );
return count( $comments );
}
$comment_count = wpse284435_comment_count_by_author( 7 );