Comments: When a comment is submitted, ensure the user_ID
element in the array that's passed to the preprocess_comment
filter gets populated.
Merges [36038] to the 4.4 branch. Fixes #34997 git-svn-id: https://develop.svn.wordpress.org/branches/4.4@36039 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5cb6bf82b8
commit
f2c9b567d9
@ -2750,7 +2750,7 @@ function wp_handle_comment_submission( $comment_data ) {
|
||||
$comment_author = $user->display_name;
|
||||
$comment_author_email = $user->user_email;
|
||||
$comment_author_url = $user->user_url;
|
||||
$user_id = $user->ID;
|
||||
$user_ID = $user->ID;
|
||||
if ( current_user_can( 'unfiltered_html' ) ) {
|
||||
if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] )
|
||||
|| ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID )
|
||||
@ -2787,7 +2787,7 @@ function wp_handle_comment_submission( $comment_data ) {
|
||||
'comment_content',
|
||||
'comment_type',
|
||||
'comment_parent',
|
||||
'user_id'
|
||||
'user_ID'
|
||||
);
|
||||
|
||||
$comment_id = wp_new_comment( wp_slash( $commentdata ) );
|
||||
|
@ -5,6 +5,8 @@
|
||||
*/
|
||||
class Tests_Comment_Submission extends WP_UnitTestCase {
|
||||
|
||||
protected $preprocess_comment_data = array();
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
require_once ABSPATH . WPINC . '/class-phpass.php';
|
||||
@ -590,4 +592,46 @@ class Tests_Comment_Submission extends WP_UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 34997
|
||||
*/
|
||||
public function test_comment_submission_sends_all_expected_parameters_to_preprocess_comment_filter() {
|
||||
|
||||
$user = self::factory()->user->create_and_get( array(
|
||||
'role' => 'author',
|
||||
) );
|
||||
wp_set_current_user( $user->ID );
|
||||
|
||||
$post = self::factory()->post->create_and_get();
|
||||
$data = array(
|
||||
'comment_post_ID' => $post->ID,
|
||||
'comment' => 'Comment',
|
||||
);
|
||||
|
||||
add_filter( 'preprocess_comment', array( $this, 'filter_preprocess_comment' ) );
|
||||
|
||||
$comment = wp_handle_comment_submission( $data );
|
||||
|
||||
remove_filter( 'preprocess_comment', array( $this, 'filter_preprocess_comment' ) );
|
||||
|
||||
$this->assertNotWPError( $comment );
|
||||
$this->assertEquals( array(
|
||||
'comment_post_ID' => $post->ID,
|
||||
'comment_author' => $user->display_name,
|
||||
'comment_author_email' => $user->user_email,
|
||||
'comment_author_url' => $user->user_url,
|
||||
'comment_content' => $data['comment'],
|
||||
'comment_type' => '',
|
||||
'comment_parent' => '0',
|
||||
'user_ID' => $user->ID,
|
||||
'user_id' => $user->ID,
|
||||
), $this->preprocess_comment_data );
|
||||
|
||||
}
|
||||
|
||||
public function filter_preprocess_comment( $commentdata ) {
|
||||
$this->preprocess_comment_data = $commentdata;
|
||||
return $commentdata;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user