Filter hook 'preprocess_comment'

in WP Core File wp-includes/comment.php at line 2294

View Source

preprocess_comment

Filter Hook
Description
Filters a comment's data before it is sanitized and inserted into the database.

Hook Information

File Location wp-includes/comment.php View on GitHub
Hook Type Filter
Line Number 2294

Hook Parameters

Type Name Description
array $commentdata Comment data.

Usage Examples

Basic Usage
<?php
// Hook into preprocess_comment
add_filter('preprocess_comment', 'my_custom_filter', 10, 1);

function my_custom_filter($commentdata) {
    // Your custom filtering logic here
    return $commentdata;
}

Source Code Context

wp-includes/comment.php:2294 - How this hook is used in WordPress core
<?php
2289  	 * @since 1.5.0
2290  	 * @since 5.6.0 Comment data includes the `comment_agent` and `comment_author_IP` values.
2291  	 *
2292  	 * @param array $commentdata Comment data.
2293  	 */
2294  	$commentdata = apply_filters( 'preprocess_comment', $commentdata );
2295  
2296  	$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
2297  
2298  	// Normalize `user_ID` to `user_id` again, after the filter.
2299  	if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) {

PHP Documentation

<?php
/**
	 * Filters a comment's data before it is sanitized and inserted into the database.
	 *
	 * @since 1.5.0
	 * @since 5.6.0 Comment data includes the `comment_agent` and `comment_author_IP` values.
	 *
	 * @param array $commentdata Comment data.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/comment.php
Related Hooks

Related hooks will be displayed here in future updates.