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'];
            $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);

**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.

  • 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... – Eugene Manuilov Aug 26 '13 at 17:10

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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