Display the number of user comments

I would like to display, on the author/user/contributor page, the number of comments the user has posted, and the number of comments he has received on his posts. Is it possible?

Thank you !

Related posts

Leave a Reply

1 comment

  1. Got some idea from here.
    User’s comments have posted

    <?php
    function commentCount() {
        global $wpdb;
        $count = $wpdb->get_var('SELECT COUNT(comment_ID) FROM ' . $wpdb-comments. ' WHERE comment_author_email = "' . get_comment_author_email() . '"');
        echo $count . ' comments';
    }
    
    commentCount();
    ?>
    

    I don’t have any idea for comments that user got from their posts. Might be use custom $wpdb query too, where post_id is array of their post id.