apply_filters( ‘preprocess_comment’, array $commentdata )

Filters a comment’s data before it is sanitized and inserted into the database.


Comment data.

More Information

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)


$commentdata = apply_filters( 'preprocess_comment', $commentdata );


5.6.0Comment data includes the comment_agent and comment_author_IP values.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    The example below remove the URL from the comment author text (comment_author_url) and changes the first character of each word of the comment content to upper case if it’s in all upper case.

    add_filter( 'preprocess_comment' , 'preprocess_comment_remove_url' );
    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'] = ucwords( strtolower( $commentdata['comment_content'] ) );
       return $commentdata;

You must log in before being able to contribute a note or feedback.