WordPress.org

Codex

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.

Description

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

Usage

<?php
   check_comment
$author$email$url$comment$user_ip,
         
$user_agent$comment_type );
?>

Parameters

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

Return Values

(boolean) 
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.

Examples

Simple use case

 <?php 
 $author = "John Charles Smith";
 $email = "jsmith@example.com";
 $url = "http://example.com";
 $comment = "Excellent...";
 $user_ip = "12.34.56.78";
 $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!";
 } 
?>

Notes

Change Log

  • Since: WordPress Version 1.2

Source File

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

Related

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