0

I have a custom comment form that inserts a comment outside of the loop and applies it to a post. I'm trying to get it to still use the moderation check before it marks as "approve". Is there a way to leverage the moderation tools with a wp_insert_comment? I'm needing to prevent comments with inappropriate words from showing up in the comment feed.

Here's my code:

add_action( 'wp_ajax_create_comment', 'create_comment' );
    function create_comment(){

        $postID = $_POST['postID'];
        $commentAuthName = $_POST['authorName'];
        $commentAuth = $_POST['authorID'];
        $commentContent = $_POST['commentContent'];
        $commentParent = $_POST['commentParent'];
        if(empty($commentParent)){
            $commentParent = 0;
        }

        $time = current_time('mysql');

        $data = array(
            'comment_post_ID' => $postID,
            'comment_content' => $commentContent,
            'comment_parent' => $commentParent,
            'comment_date' => $time,
            'comment_approved' => 1,
            'user_id' => $commentAuth,
            'comment_author' => $commentAuthName,
            'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
            'comment_agent' => $_SERVER['HTTP_USER_AGENT'],
        );

        $commentID = wp_insert_comment($data);
        print_r($commentID);
        die();
    }

**Adding additional clarification: I want to automatically publish and display contents that are not flagged based on the moderation keys. The ones that are flagged, need to be sent to the moderation que.

1
  • So what is the issue? Or you just want us to code it for u? Although your question is too generic, the answer on it will requires a lot of work and will be quite big... Commented Aug 26, 2013 at 17:10

1 Answer 1

0

Just to close this out, the answer is very easy in that, yes it is possible and here's the function that does the check to see if the comment passes the moderation verification or not. Then you can add a conditional and either add the comment or not based on that.

check_comment(); Function reference: http://codex.wordpress.org/Function_Reference/check_comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.