Advertisements

wp_insert_comment

Definition:
function wp_insert_comment($commentdata) {}

Inserts a comment to the database.
The available comment data key names are ‘comment_author_IP’, ‘comment_date’, ‘comment_date_gmt’, ‘comment_parent’, ‘comment_approved’, and ‘user_id’.

Parameters

  • array $commentdata: Contains information on the comment.

Return values

returns:The new comment’s ID.

Defined actions

  • wp_insert_comment
    do_action('wp_insert_comment', $id, $comment);

Source code

function wp_insert_comment($commentdata) {

	global $wpdb;

	extract(stripslashes_deep($commentdata), EXTR_SKIP);



	if ( ! isset($comment_author_IP) )

		$comment_author_IP = '';

	if ( ! isset($comment_date) )

		$comment_date = current_time('mysql');

	if ( ! isset($comment_date_gmt) )

		$comment_date_gmt = get_gmt_from_date($comment_date);

	if ( ! isset($comment_parent) )

		$comment_parent = 0;

	if ( ! isset($comment_approved) )

		$comment_approved = 1;

	if ( ! isset($comment_karma) )

		$comment_karma = 0;

	if ( ! isset($user_id) )

		$user_id = 0;

	if ( ! isset($comment_type) )

		$comment_type = '';



	$data = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id');

	$wpdb->insert($wpdb->comments, $data);



	$id = (int) $wpdb->insert_id;



	if ( $comment_approved == 1 )

		wp_update_comment_count($comment_post_ID);



	$comment = get_comment($id);

	do_action('wp_insert_comment', $id, $comment);



	return $id;

}

3789

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: