wp_new_comment() WP 1.0
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 https://core.trac.wordpress.org/ticket/9235
Hooks from the function
Return
Int/false/WP_Error. The ID of the comment on success, false or WP_Error on failure.
Usage
wp_new_comment( $commentdata, $wp_error );
- $commentdata(array) (required)
Comment data.
-
comment_author(string)
The name of the comment author. -
comment_author_email(string)
The comment author email address. -
comment_author_url(string)
The comment author URL. -
comment_content(string)
The content of the comment. -
comment_date(string)
The date the comment was submitted.
Default: current time -
comment_date_gmt(string)
The date the comment was submitted in the GMT timezone.
Default: $comment_date in the GMT timezone -
comment_type(string)
Comment type.
Default: 'comment' -
comment_parent(int)
The ID of this comment's parent, if any. -
comment_post_ID(int)
The ID of the post that relates to the comment. -
user_id(int)
The ID of the user who submitted the comment. -
user_ID(int)
Kept for backward-compatibility. Use $user_id instead. -
comment_agent(string)
Comment author user agent.
Default: value of 'HTTP_USER_AGENT' in the $_SERVER superglobal sent in the original request - comment_author_IP(string)
Comment author IP address in IPv4 format.
Default: value of 'REMOTE_ADDR' in the $_SERVER superglobal sent in the original request
-
- $wp_error(true/false)
- Should errors be returned as WP_Error objects instead of executing wp_die()? Default false.
Default: false
Notes
- See: wp_insert_comment()
- Global. wpdb. $wpdb WordPress database abstraction object.
Changelog
Since 1.5.0 | Introduced. |
Since 4.3.0 | Introduced the comment_agent and comment_author_IP arguments. |
Since 4.7.0 | The $avoid_die parameter was added, allowing the function to return a WP_Error object instead of dying. |
Since 5.5.0 | The $avoid_die parameter was renamed to $wp_error. |
Since 5.5.0 | Introduced the comment_type argument. |
Code of wp_new_comment() wp new comment WP 5.6
Related Functions
From category: Comments
- cancel_comment_reply_link()
- comment_author_email_link()
- comment_form()
- comment_form_title()
- comment_id_fields()
- comment_text()
- comment_type()
- comments_link()
- comments_number()
- comments_popup_link()
- get_avatar()
- get_avatar_data()
- get_avatar_url()
- get_cancel_comment_reply_link()
- get_comment()
- get_comment_author_email()
- get_comment_pages_count()
- get_comment_reply_link()
- get_comment_text()
- get_comment_type()
- get_comments()
- get_comments_link()
- get_comments_number()
- get_comments_pagenum_link()
- get_edit_comment_link()
- get_next_comments_link()
- get_page_of_comment()
- get_previous_comments_link()
- get_the_comments_navigation()
- get_the_comments_pagination()
- is_comment_feed()
- is_trackback()
- next_comments_link()
- paginate_comments_links()
- previous_comments_link()
- sanitize_comment_cookies()
- the_comments_navigation()
- the_comments_pagination()
- wp_allow_comment()
- wp_count_comments()
- wp_delete_comment()
- wp_get_current_commenter()
- wp_handle_comment_submission()
- wp_insert_comment()
- wp_list_comments()
- wp_notify_moderator()
- wp_notify_postauthor()
- wp_set_comment_cookies()
- wp_set_comment_status()
- wp_spam_comment()
- wp_transition_comment_status()
- wp_update_comment()
- wp_update_comment_count()