wp_new_comment ( $commentdata, $avoid_die = false )

  • (array) $commentdata { Comment data.
  • (bool) $avoid_die Should errors be returned as WP_Error objects instead of executing wp_die()? Default false.
  • (int|false|WP_Error) The ID of the comment on success, false or WP_Error on failure.
Defined at:
Change Log:
  • 4: .
  • 4: .


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 {@see 'comment_post'} action with comment ID and whether comment is approved by WordPress. Also has {@see '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 https://core.trac.wordpress.org/ticket/9235}

Related Functions

wp_insert_comment, wp_allow_comment, wp_delete_comment, wp_filter_comment, wp_unspam_comment

Top Google Results

User discussions

wpseek mobile