wp_filter_comment

Filters and sanitizes comment data.

Description

(array) wp_filter_comment( (array) $commentdata ); 

Sets the comment data filtered field to true when finished. This can be checked as to whether the comment should be filtered and to keep from filtering the same comment more than once.

Returns (array)

Parsed comment information.

Parameters (1)

0. $commentdata (array)
Contains information on the comment.

Usage

  1. if ( !function_exists( 'wp_filter_comment' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // Contains information on the comment. 
  5. $commentdata = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_filter_comment($commentdata); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment.php  
  1. function wp_filter_comment($commentdata) { 
  2. if ( isset( $commentdata['user_ID'] ) ) { 
  3. /** 
  4. * Filters the comment author's user id before it is set. 
  5. * The first time this filter is evaluated, 'user_ID' is checked 
  6. * (for back-compat), followed by the standard 'user_id' value. 
  7. * @since 1.5.0 
  8. * @param int $user_ID The comment author's user ID. 
  9. */ 
  10. $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] ); 
  11. } elseif ( isset( $commentdata['user_id'] ) ) { 
  12. /** This filter is documented in wp-includes/comment.php */ 
  13. $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] ); 
  14.  
  15. /** 
  16. * Filters the comment author's browser user agent before it is set. 
  17. * @since 1.5.0 
  18. * @param string $comment_agent The comment author's browser user agent. 
  19. */ 
  20. $commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) ); 
  21. /** This filter is documented in wp-includes/comment.php */ 
  22. $commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] ); 
  23. /** 
  24. * Filters the comment content before it is set. 
  25. * @since 1.5.0 
  26. * @param string $comment_content The comment content. 
  27. */ 
  28. $commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] ); 
  29. /** 
  30. * Filters the comment author's IP before it is set. 
  31. * @since 1.5.0 
  32. * @param string $comment_author_ip The comment author's IP. 
  33. */ 
  34. $commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] ); 
  35. /** This filter is documented in wp-includes/comment.php */ 
  36. $commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] ); 
  37. /** This filter is documented in wp-includes/comment.php */ 
  38. $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] ); 
  39. $commentdata['filtered'] = true; 
  40. return $commentdata;