A filter-hook that is applied to the comment data prior to any other processing of the comment's information when saving a comment data to the database.
<?php
function preprocess_comment_handler( $commentdata ) {
//some code
return $commentdata;
}
add_filter( 'preprocess_comment' , 'preprocess_comment_handler' );
?>
The $commentdata array contains the following indices:
'comment_post_ID' - The post to which the comment will apply 'comment_author' - (may be empty) 'comment_author_email' - (may be empty) 'comment_author_url' - (may be empty) 'comment_content' - The text of the proposed comment 'comment_type' - 'pingback', 'trackback', or empty for regular comments 'user_ID' - (empty if not logged in)
<?php
function preprocess_comment_remove_url( $commentdata ) {
// Always remove the URL from the comment author's comment
unset( $commentdata['comment_author_url'] );
// If the user is speaking in all caps, lowercase the comment
if( $commentdata['comment_content'] == strtoupper( $commentdata['comment_content'] )) {
$commentdata['comment_content'] = strtolower( $commentdata['comment_content'] );
}
return $commentdata;
}
add_filter( 'preprocess_comment' , 'preprocess_comment_remove_url' );
?>
(pre_process_comment) Since: 1.5.2
Prior to WP 2.0, the hook was located in wp-includes/function-post.php Prior to WP 2.1, the hook was located in wp-includes/comment-functions.php
The preprocess_comment comment is located in wp-includes/comment.php
.