Support » Requests and Feedback » Allow a Subscriber to post 1 comment per post

  • Hi Guys,
    I have setup a review site. and a rating plugin that uses the wordpress comments. only logged in (subcriber role) useres can comment.All works fine.

    I want to allow a user to submit one review per post. this way they cannot vote multiple times thus stopping spamming.

    I tried this

    <?php
    global $current_user;
    $args = array('user_id' => $current_user->ID);
    $usercomment = get_comments($args);
    if(count($usercomment) >= 1){
    	echo 'disabled';
    } else {
    	comment_form();
    }
    ?>

    from this thread – https://wordpress.org/support/topic/one-comment-per-user-per-post/

    I also tried this plugin – https://wordpress.org/plugins/limit-comments-and-word-count/

    Then Found this

    /* ------------------------------------------------
       *  One Comment per post
    --------------------------------------------------- */
    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);

    This last code put on the functions.php of the theme file seems working. but is there any safe plugin to get this same thing done? or what if wordpress can have this incorporated. so that with tick anyone can get this functionality.

    I think this is a great way to cut down spammers.

    • This topic was modified 2 months, 3 weeks ago by anandaxp.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.