apply_filters( 'preprocess_comment', array $commentdata )

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


Parameters Parameters

$commentdata

(array) Comment data.


Top ↑

More Information 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)


Top ↑

Source Source

File: wp-includes/comment.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
5.6.0 Comment data includes the comment_agent and comment_author_IP values.
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    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' );
    
    <?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'] = ucwords( strtolower( $commentdata['comment_content'] ) );
       }
    
       return $commentdata;
    }
    ?>
    

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