From 14ba67c38d3cbba6b2cfab85d651f3a4529d39b1 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 16 May 2014 18:52:16 +0000 Subject: [PATCH] Eliminate use of `extract()` in `wp_insert_comment()`. See #22400. Built from https://develop.svn.wordpress.org/trunk@28457 git-svn-id: http://core.svn.wordpress.org/trunk@28284 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 7a9645a7e2..d0f8e08f4f 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -832,7 +832,7 @@ function wp_allow_comment( $commentdata ) { } else { $approved = 0; } - + if ( wp_blacklist_check( $commentdata['comment_author'], $commentdata['comment_author_email'], @@ -1553,36 +1553,37 @@ function wp_get_current_commenter() { * @param array $commentdata Contains information on the comment. * @return int The new comment's ID. */ -function wp_insert_comment($commentdata) { +function wp_insert_comment( $commentdata ) { global $wpdb; - extract(wp_unslash($commentdata), EXTR_SKIP); + $data = wp_unslash( $commentdata ); - 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 = ''; + $comment_author = ! isset( $data['comment_author'] ) ? '' : $data['comment_author']; + $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email']; + $comment_author_url = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url']; + $comment_author_IP = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP']; - $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'); - $wpdb->insert($wpdb->comments, $data); + $comment_date = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date']; + $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt']; + + $comment_post_ID = ! isset( $data['comment_post_ID'] ) ? '' : $data['comment_post_ID']; + $comment_content = ! isset( $data['comment_content'] ) ? '' : $data['comment_content']; + $comment_karma = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma']; + $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved']; + $comment_agent = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent']; + $comment_type = ! isset( $data['comment_type'] ) ? '' : $data['comment_type']; + $comment_parent = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent']; + + $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id']; + + $compacted = 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' ); + $wpdb->insert( $wpdb->comments, $compacted ); $id = (int) $wpdb->insert_id; - if ( $comment_approved == 1 ) - wp_update_comment_count($comment_post_ID); - - $comment = get_comment($id); + if ( $comment_approved == 1 ) { + wp_update_comment_count( $comment_post_ID ); + } + $comment = get_comment( $id ); /** * Fires immediately after a comment is inserted into the database.