Limit comments per user per post

I think that hook pre_comment_approved should be perfect in this case.

Something like this should do the job:

function my_pre_comment_approved($approved, $commentdata) {
    // you can return 0, 1 or 'spam'
    if ( $commentdata['user_ID'] ) {
        $args = array(
            'user_id' => $commentdata['user_ID'],
            'post_id' => $commentdata['comment_post_ID']
        );
        $usercomment = get_comments( $args );
        if ( 1 <= count( $usercomment ) )
            return 0;
    }
    return $approved;
}
add_filter('pre_comment_approved', 'my_pre_comment_approved', 99, 2);

Your filter should return:

  • 0 (i.e. ‘false’) if the comment should be disapproved
  • 1 (i.e. ‘true’) if the comment should be approved
  • 'spam' if the comment should be marked as spam

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)