Index: wp-includes/comment.php
===================================================================
--- wp-includes/comment.php	(revision 24827)
+++ wp-includes/comment.php	(working copy)
@@ -1255,33 +1255,41 @@
  * 'comment_date_gmt', 'comment_parent', 'comment_approved', and 'user_id'.
  *
  * @since 2.0.0
+ * @uses apply_filters() Calls 'wp_insert_comment_data' hook with comment data prior to insertion
+ * @uses do_action() Calls 'wp_insert_comment' hook with inserted comment ID and comment object
  * @uses $wpdb
  *
  * @param array $commentdata Contains information on the comment.
- * @return int The new comment's ID.
+ * @return int|WP_Error The new comment's ID, or instance of WP_Error
  */
 function wp_insert_comment($commentdata) {
 	global $wpdb;
-	extract(wp_unslash($commentdata), EXTR_SKIP);
+	$commentdata = wp_unslash( $commentdata );
+	$defaults = array(
+		'comment_post_ID' => null,
+		'comment_author' => '',
+		'comment_author_email' => '',
+		'comment_author_url' => '',
+		'comment_author_IP' => '',
+		'comment_date' => current_time( 'mysql', false ),
+		'comment_date_gmt' => current_time( 'mysql', true ),
+		'comment_content' => '',
+		'comment_karma' => 0,
+		'comment_approved' => 1,
+		'comment_agent' => '',
+		'comment_type' => '',
+		'comment_parent' => 0,
+		'user_id' => 0,
+	);
+	$commentdata = array_merge( $defaults, $commentdata );
+	$data = array_intersect_key( $commentdata, $defaults );
+	$data = apply_filters( 'wp_insert_comment_data', $data );
+	extract($data, 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 = '';
+	if ( empty( $comment_post_ID ) || ! get_post( $comment_post_ID ) ) {
+		return new WP_Error( 'invalid_comment_post_id', __( 'Missing or invalid comment_post_ID' ) );
+	}
 
-	$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;
