Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/check comment

This article is marked as in need of editing. You can help Codex by editing it.


check_comment() checks whether a comment passes internal checks set by WordPress Comment_Moderation.


$user_agent$comment_type );


(string) (required) Comment author name.
Default: None
(string) (required) Comment author email.
Default: None
(string) (required) Comment author URL.
Default: None
(string) (required) Comment contents.
Default: None
(string) (required) Comment author IP address.
Default: None
(string) (required) Comment author user agent.
Default: None
(string) (required) Comment type (comment, trackback, or pingback).
Default: None

Return Values

This function returns a single boolean value of either true or false.

Returns false if in Comment_Moderation:

  • The Administrator must approve all messages,
  • The number of external links is too high, or
  • Any banned word, name, URL, e-mail, or IP is found in any parameter except $comment_type.

Returns true if the Administrator does not have to approve all messages and:

  • $comment_type parameter is a trackback or pingback and part of the blogroll, or
  • $author and $email parameters have been approved previously.

Returns true in all other cases.


Simple use case

 $author = "John Charles Smith";
 $email = "jsmith@example.com";
 $url = "http://example.com";
 $comment = "Excellent...";
 $user_ip = "";
 $user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11";
 $comment_type = "comment";
 if (check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type )) {
   echo "The Comment robot says: Thank you for your comment.";
 } else {
   echo "The Comment robot says: This comment is NOT valid!";


Change Log

  • Since: WordPress Version 1.2

Source File

check_comment() is located in wp-includes/comment.php.


See also index of Function Reference and index of Template Tags.