A method in a plugin uses preprocess_comment but that commentdata array does not have comment_approved because the comment hasn't been recorded. I'm trying to rewrite the method using pre_comment_on_post but noticing that the information returned is the comment_post_ID.

How can the comment_post_ID be used to grab the array of the commentdata only for the comment which is going to be written to WP?

I've tried get_comments but it pulls everything but the comment about to be written. Here is a snippet of code which shows the var_dump is the comment_post_ID.

public function hooks() {
    add_action( 'pre_comment_on_post', array( $this, 'write' ), 10, 1 );

public function write( $comment_post_ID ) {

Maybe there is a better way to grab the comment and post it externally then have it written to WordPress.

1 Answer 1


You can use the preprocess_comment inside wp_new_comment() filter to access/modify the data of the comment that is going to be written.


 * Filters a comment's data before it is sanitized and inserted into the database.
 * @since 1.5.0
 * @param array $commentdata Comment data.
$commentdata = apply_filters( 'preprocess_comment', $commentdata );

just make sure you hook after the plugin in question (using a greater priority) in order your filter to come afterwards whatever the plugin does to $commentdata or before it (using a lower filter priority) if you need to process $commentdata before it's passed to the plugin. See add_filter's docs if $priority argument is new to you.

  • Thank you but all the var dumps show that the preprocess_comment data does not have comment_approved. It is preprocessing before approval. I've rewritten the function to use comment_post and it works.
    – LPH
    Nov 18, 2016 at 14:35

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.