Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Restrict each commenter to create/reply to 1 thread only WordPress

I'm looking for a function that restricts each commenter to <strong>only create one thread</strong>. The commenter may reply as much as they like but only inside the current thread they created.

Answers (2)

2016-04-15

Shoeb mirza answers:

So in Functions.php add

function c_parent_comment_counter($pid,$uid){
global $wpdb;
$query = "SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE comment_approved = 1 AND comment_post_ID= $pid AND user_id = $uid AND comment_parent = 0";
$parents = $wpdb->get_row($query);
return $parents->count;
</blockquote>

and in comments.php

global $current_user, $post;
$number_of_parents = c_parent_comment_counter($post->ID,$current_user->ID);
echo "parents: ".$number_of_parents;
if ( $number_of_parents >= 1 ) {
echo '<nav class="withcomment">';
comment_form( array( 'title_reply' => __( 'Reply' ) ) );
echo '</nav>';
} else {
echo '<span class="withoutcomment">' . comment_form( array( 'title_reply' => __( 'Your opinion' ) ) ) . '</span>';
}


in style.css
.withcomment {
display: none;
}


Try this and let me know if it fix for you?


pjeaje comments:

Sorry I need this to work with the native WP comments. If I change the comment.php it will affect other plugins


pjeaje comments:

Create 1 thread AND only reply to this same thread

2016-04-15

Reigel Gallarde answers:

users can't comment to other thread?


pjeaje comments:

Correct, only REPLY to their own thread


pjeaje comments:

Create 1 thread AND only reply to this same thread