Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_insert_comment [ WordPress Function ]

wp_insert_comment ( $commentdata )
Parameters:
  • (array) $commentdata Contains information on the comment.
Uses:
  • $wpdb
Returns:
  • (int) The new comment's ID.
Defined at:



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'.

Source


<?php
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 == )
        
wp_update_comment_count($comment_post_ID);

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

    return 
$id;
}
?>

Examples [ wp-snippets.com ]

Top Google Search Results

More ...

User discussions [ wordpress.org ]

0 User Note(s)

None yet. Be the first!

Add New ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics