WordPress.org

Ready to get started?Download WordPress

Codex

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

Function Reference/wp new comment

Contents

Description

Adds a new comment to the database.

Filters new comment to ensure that the fields are sanitized and valid before inserting comment into database. Calls 'comment_post' action with comment ID and whether comment is approved by WordPress. Also has 'preprocess_comment' filter for processing the comment data before the function handles it.

Usage

<?php wp_new_comment$commentdata ?>

Parameters

$commentdata
(array) (required) Contains information on the comment.
Default: None

Return Values

(integer) 
The ID of the comment after adding.

Examples

$commentdata = compact(
	'comment_post_ID',
	'comment_author', 
	'comment_author_email', 
	'comment_author_url', 
	'comment_content',
	'comment_type',
	'comment_parent',
	'user_id',
	'comment_author_IP'
);
/**
 * Insert new comment and get the comment ID
 */
$comment_id = wp_new_comment($commentdata);

Notes

Change Log

Since: 1.5.0

Source File

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

Related

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