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.