wp_new_comment [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| 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 = ( 0 < $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'], 0, 254);
$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
- Function Reference/wp new comment « WordPress Codex
Description. Adds a new comment to the database. Filters new comment to ensure that the fields are sanitized and valid before inserting comment into database.
codex.wordpress.org - WordPress › Support » wp_new_comment will not insert my variables
I have a custom module I've created and need to insert data into wp_comments. The insert works, but SOME variables are ending up as empty values in the db.
wordpress.org - #14601 (wp_new_comment method doesn't allow passed in values ...
In a scenario where you have a client that receives comments from the internet and pre-processes those comments before feeding them into wordpress through ...
core.trac.wordpress.org - wp_new_comment (WordPress Function) - WPSeek.com
WordPress lookup for wp_new_comment, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com