Switch language

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




wp_new_comment [ WordPress Function ]

wp_new_comment ( $commentdata )
Parameters:
  • (array) $commentdata Contains information on the comment.
Uses:
Returns:
  • (int) The ID of the comment after adding.
Defined at:



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.

We use REMOTE_ADDR here directly. If you are behind a proxy, you should ensure that it is properly set, such as in wp-config.php, for your environment. See {@link http://core.trac.wordpress.org/ticket/9235}

Source


<?php
function wp_new_comment$commentdata ) {
    
$commentdata apply_filters('preprocess_comment'$commentdata);

    
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
    if ( isset(
$commentdata['user_ID']) )
        
$commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    elseif ( isset(
$commentdata['user_id']) )
        
$commentdata['user_id'] = (int) $commentdata['user_id'];

    
$commentdata['comment_parent'] = isset($commentdata['comment_parent']) ? absint($commentdata['comment_parent']) : 0;
    
$parent_status = ( $commentdata['comment_parent'] ) ? wp_get_comment_status($commentdata['comment_parent']) : '';
    
$commentdata['comment_parent'] = ( 'approved' == $parent_status || 'unapproved' == $parent_status ) ? $commentdata['comment_parent'] : 0;

    
$commentdata['comment_author_IP'] = preg_replace'/[^0-9a-fA-F:., ]/''',$_SERVER['REMOTE_ADDR'] );
    
$commentdata['comment_agent']     = substr($_SERVER['HTTP_USER_AGENT'], 0254);

    
$commentdata['comment_date']     = current_time('mysql');
    
$commentdata['comment_date_gmt'] = current_time('mysql'1);

    
$commentdata wp_filter_comment($commentdata);

    
$commentdata['comment_approved'] = wp_allow_comment($commentdata);

    
$comment_ID wp_insert_comment($commentdata);

    
do_action('comment_post'$comment_ID$commentdata['comment_approved']);

    if ( 
'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching
        
if ( '0' == $commentdata['comment_approved'] )
            
wp_notify_moderator($comment_ID);

        
$post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment

        
if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )
            
wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
    }

    return 
$comment_ID;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



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