WordPress filter hook · part of WordPress core

preprocess_comment

A WordPress core filter that 11 plugins also fire themselves, running on 41K+ sites between them.

“Filter a comment's data before it is sanitized and inserted into the database.”

How to use preprocess_comment

It's a filter: your callback receives the value, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'preprocess_comment', function( $commentdata ) {
	// Change $commentdata here.
	return $commentdata;
}, 10, 1 );

Argument names come from MediaPress's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

11 plugins that fire preprocess_comment

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Kadence Central icon Kadence Central30,000+ installs apply_filters( 'preprocess_comment', $comment ) verbs/manage-comments.php:271
  2. Contact Form Clean and Simple icon Contact Form Clean and Simple7,000+ installs apply_filters( 'preprocess_comment', array( 'comment_post_ID' => $contact->PostID, 'comment_author' => $contact->Name, 'comment_author_email' => $contact->Email, 'comment_content' => $contact->Message, 'comment_type' => 'contact-form', 'comment_author_url' => '', ) ) class.cscf.php:181
  3. MediaPress icon MediaPress3,000+ installs apply_filters( 'preprocess_comment', $commentdata ) core/comments/mpp-comment-functions.php:172
  4. Recapture for Easy Digital Downloads icon Recapture for Easy Digital Downloads500+ installs apply_filters( 'preprocess_comment', $args ) platforms/class-edd.php:557
  5. WP-United : phpBB WordPress Integration icon WP-United : phpBB WordPress Integration100+ installs apply_filters( 'preprocess_comment', $commentData ) cross-posting.php:880
  6. MDJM Event Management icon MDJM Event Management50+ installs apply_filters( 'preprocess_comment', $comment_data ) includes/journal-functions.php:67
  7. Securicheck icon Securicheck50+ installs apply_filters( 'preprocess_comment', $commentdata ) utils/antiSpamCommentaires.php:226
  8. Twitter Mentions As Comments icon Twitter Mentions As Comments30+ installs apply_filters( 'preprocess_comment', $commentdata ) twitter-mentions-as-comments.php:385
  9. IntenseDebate XML Importer (Blogger to WordPress) icon IntenseDebate XML Importer (Blogger to WordPress)10+ installs apply_filters( 'preprocess_comment', $commentdata ) id_import_blg_wp.php:158
  10. Redmatrix_WP icon Redmatrix_WPFewer than 10 installs apply_filters( 'preprocess_comment', $commentdata ) redmatrix-wp.php:620
  11. Dessky reCAPTCHA icon Dessky reCAPTCHAFewer than 10 installs do_action( 'preprocess_comment', $commentdata ) dessky-recaptcha.php:170
  12. Zu Contact icon Zu ContactFewer than 10 installs apply_filters( 'preprocess_comment', [ 'comment_post_ID' => $contact->post_id, 'comment_author' => $contact->name, 'comment_author_email' => $contact->email, 'comment_content' => $contact->message, 'comment_type' => 'zu-contact', 'comment_parent' => 0, 'comment_author_url' => '', ] ) includes/traits/mailer.php:42

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.