diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 8899dc30e8..9629c58a28 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -1742,6 +1742,11 @@ function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) * @return int|bool The ID of the comment on success, false on failure. */ function wp_new_comment( $commentdata ) { + if ( isset( $commentdata['user_ID'] ) ) { + $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; + } + $prefiltered_user_id = $commentdata['user_id']; + /** * Filter a comment's data before it is sanitized and inserted into the database. * @@ -1752,10 +1757,11 @@ 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']) ) + if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) { $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; - elseif ( isset($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']) : '';