wp_insert_comment

The timeline below displays how wordpress function wp_insert_comment has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced the `$comment_meta` argument.
 * @since 5.5.0 Default value for `$comment_type` argument changed to `comment`.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default 0.
 *     @type string     $comment_type         Comment type. Default 'comment'.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_ip = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_id = (!isset($data['comment_post_ID'])) ? 0 : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = empty($data['comment_type']) ? 'comment' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = array('comment_post_ID' => $comment_post_id, 'comment_author_IP' => $comment_author_ip);
    $compacted += compact('comment_author', 'comment_author_email', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if (1 == $comment_approved) {
        wp_update_comment_count($comment_post_id);
        $data = array();
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            $data[] = "lastcommentmodified:{$timezone}";
        }
        wp_cache_delete_multiple($data, 'timeinfo');
    }
    clean_comment_cache($id);
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    return $id;
}

WordPress Version: 5.5

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced the `$comment_meta` argument.
 * @since 5.5.0 Default value for `$comment_type` argument changed to `comment`.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default 0.
 *     @type string     $comment_type         Comment type. Default 'comment'.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? 0 : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = empty($data['comment_type']) ? 'comment' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if (1 == $comment_approved) {
        wp_update_comment_count($comment_post_ID);
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastcommentmodified:{$timezone}", 'timeinfo');
        }
    }
    clean_comment_cache($id);
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    return $id;
}

WordPress Version: 5.4

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced `$comment_meta` argument.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default 0.
 *     @type string     $comment_type         Comment type. Default empty.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? 0 : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if (1 == $comment_approved) {
        wp_update_comment_count($comment_post_ID);
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastcommentmodified:{$timezone}", 'timeinfo');
        }
    }
    clean_comment_cache($id);
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    return $id;
}

WordPress Version: 4.7

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced `$comment_meta` argument.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default 0.
 *     @type string     $comment_type         Comment type. Default empty.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? 0 : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastcommentmodified:{$timezone}", 'timeinfo');
        }
    }
    clean_comment_cache($id);
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    return $id;
}

WordPress Version: 4.6

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced `$comment_meta` argument.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default 0.
 *     @type string     $comment_type         Comment type. Default empty.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? 0 : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    clean_comment_cache($id);
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    return $id;
}

WordPress Version: 4.5

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced `$comment_meta` argument.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default 0.
 *     @type string     $comment_type         Comment type. Default empty.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? 0 : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 4.4

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 * @since 4.4.0 Introduced `$comment_meta` argument.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default empty.
 *     @type string     $comment_type         Comment type. Default empty.
 *     @type array      $comment_meta         Optional. Array of key/value pairs to be stored in commentmeta for the
 *                                            new comment.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? '' : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    // If metadata is provided, store it.
    if (isset($commentdata['comment_meta']) && is_array($commentdata['comment_meta'])) {
        foreach ($commentdata['comment_meta'] as $meta_key => $meta_value) {
            add_comment_meta($comment->comment_ID, $meta_key, $meta_value, true);
        }
    }
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int        $id      The comment ID.
     * @param WP_Comment $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 4.3

/**
 * Inserts a comment into the database.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata {
 *     Array of arguments for inserting a new comment.
 *
 *     @type string     $comment_agent        The HTTP user agent of the `$comment_author` when
 *                                            the comment was submitted. Default empty.
 *     @type int|string $comment_approved     Whether the comment has been approved. Default 1.
 *     @type string     $comment_author       The name of the author of the comment. Default empty.
 *     @type string     $comment_author_email The email address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_IP    The IP address of the `$comment_author`. Default empty.
 *     @type string     $comment_author_url   The URL address of the `$comment_author`. Default empty.
 *     @type string     $comment_content      The content of the comment. Default empty.
 *     @type string     $comment_date         The date the comment was submitted. To set the date
 *                                            manually, `$comment_date_gmt` must also be specified.
 *                                            Default is the current time.
 *     @type string     $comment_date_gmt     The date the comment was submitted in the GMT timezone.
 *                                            Default is `$comment_date` in the site's GMT timezone.
 *     @type int        $comment_karma        The karma of the comment. Default 0.
 *     @type int        $comment_parent       ID of this comment's parent, if any. Default 0.
 *     @type int        $comment_post_ID      ID of the post that relates to the comment, if any.
 *                                            Default empty.
 *     @type string     $comment_type         Comment type. Default empty.
 *     @type int        $user_id              ID of the user who submitted the comment. Default 0.
 * }
 * @return int|false The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? '' : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int $id      The comment ID.
     * @param obj $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: .10

/**
 * 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'.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata Contains information on the comment.
 * @return int|bool The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? '' : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int $id      The comment ID.
     * @param obj $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 4.2

/**
 * 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'.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata Contains information on the comment.
 * @return int|bool The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? '' : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        $fields = array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_content');
        foreach ($fields as $field) {
            if (isset($compacted[$field])) {
                $compacted[$field] = $wpdb->strip_invalid_text_for_column($wpdb->comments, $field, $compacted[$field]);
            }
        }
        if (!$wpdb->insert($wpdb->comments, $compacted)) {
            return false;
        }
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int $id      The comment ID.
     * @param obj $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 4.1

/**
 * 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'.
 *
 * @since 2.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $commentdata Contains information on the comment.
 * @return int|bool The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? '' : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int $id      The comment ID.
     * @param obj $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 4.0

/**
 * 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'.
 *
 * @since 2.0.0
 * @uses $wpdb
 *
 * @param array $commentdata Contains information on the comment.
 * @return int|bool The new comment's ID on success, false on failure.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    $data = wp_unslash($commentdata);
    $comment_author = (!isset($data['comment_author'])) ? '' : $data['comment_author'];
    $comment_author_email = (!isset($data['comment_author_email'])) ? '' : $data['comment_author_email'];
    $comment_author_url = (!isset($data['comment_author_url'])) ? '' : $data['comment_author_url'];
    $comment_author_IP = (!isset($data['comment_author_IP'])) ? '' : $data['comment_author_IP'];
    $comment_date = (!isset($data['comment_date'])) ? current_time('mysql') : $data['comment_date'];
    $comment_date_gmt = (!isset($data['comment_date_gmt'])) ? get_gmt_from_date($comment_date) : $data['comment_date_gmt'];
    $comment_post_ID = (!isset($data['comment_post_ID'])) ? '' : $data['comment_post_ID'];
    $comment_content = (!isset($data['comment_content'])) ? '' : $data['comment_content'];
    $comment_karma = (!isset($data['comment_karma'])) ? 0 : $data['comment_karma'];
    $comment_approved = (!isset($data['comment_approved'])) ? 1 : $data['comment_approved'];
    $comment_agent = (!isset($data['comment_agent'])) ? '' : $data['comment_agent'];
    $comment_type = (!isset($data['comment_type'])) ? '' : $data['comment_type'];
    $comment_parent = (!isset($data['comment_parent'])) ? 0 : $data['comment_parent'];
    $user_id = (!isset($data['user_id'])) ? 0 : $data['user_id'];
    $compacted = 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');
    if (!$wpdb->insert($wpdb->comments, $compacted)) {
        return false;
    }
    $id = (int) $wpdb->insert_id;
    if ($comment_approved == 1) {
        wp_update_comment_count($comment_post_ID);
    }
    $comment = get_comment($id);
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int $id      The comment ID.
     * @param obj $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 3.8

/**
 * 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'.
 *
 * @since 2.0.0
 * @uses $wpdb
 *
 * @param array $commentdata Contains information on the comment.
 * @return int The new comment's ID.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    extract(wp_unslash($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);
    /**
     * Fires immediately after a comment is inserted into the database.
     *
     * @since 2.8.0
     *
     * @param int $id      The comment ID.
     * @param obj $comment Comment object.
     */
    do_action('wp_insert_comment', $id, $comment);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}

WordPress Version: 3.7

/**
 * 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'.
 *
 * @since 2.0.0
 * @uses $wpdb
 *
 * @param array $commentdata Contains information on the comment.
 * @return int The new comment's ID.
 */
function wp_insert_comment($commentdata)
{
    global $wpdb;
    extract(wp_unslash($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);
    wp_cache_set('last_changed', microtime(), 'comment');
    return $id;
}