Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: xwp/WordPress-deprecated
...
head fork: xwp/WordPress-deprecated
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 29 additions and 21 deletions.
  1. +29 −21 wp-includes/comment.php
View
50 wp-includes/comment.php
@@ -1255,33 +1255,41 @@ function wp_get_current_commenter() {
* 'comment_date_gmt', 'comment_parent', 'comment_approved', and 'user_id'.
*
* @since 2.0.0
+ * @uses apply_filters() Calls 'wp_insert_comment_data' hook with comment data prior to insertion
+ * @uses do_action() Calls 'wp_insert_comment' hook with inserted comment ID and comment object
* @uses $wpdb
*
* @param array $commentdata Contains information on the comment.
- * @return int The new comment's ID.
+ * @return int|WP_Error The new comment's ID, or instance of WP_Error
*/
function wp_insert_comment($commentdata) {
global $wpdb;
- extract(wp_unslash($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');
+ $commentdata = wp_unslash( $commentdata );
+ $defaults = array(
+ 'comment_post_ID' => null,
+ 'comment_author' => '',
+ 'comment_author_email' => '',
+ 'comment_author_url' => '',
+ 'comment_author_IP' => '',
+ 'comment_date' => current_time( 'mysql', false ),
+ 'comment_date_gmt' => current_time( 'mysql', true ),
+ 'comment_content' => '',
+ 'comment_karma' => 0,
+ 'comment_approved' => 1,
+ 'comment_agent' => '',
+ 'comment_type' => '',
+ 'comment_parent' => 0,
+ 'user_id' => 0,
+ );
+ $commentdata = array_merge( $defaults, $commentdata );
+ $data = array_intersect_key( $commentdata, $defaults );
+ $data = apply_filters( 'wp_insert_comment_data', $data );
+ extract($data, EXTR_SKIP);
+
+ if ( empty( $comment_post_ID ) || ! get_post( $comment_post_ID ) ) {
+ return new WP_Error( 'invalid_comment_post_id', __( 'Missing or invalid comment_post_ID' ) );
+ }
+
$wpdb->insert($wpdb->comments, $data);
$id = (int) $wpdb->insert_id;

No commit comments for this range

Something went wrong with that request. Please try again.