WordPress.org

Make WordPress Core

Changeset 36039


Ignore:
Timestamp:
12/21/2015 02:57:06 AM (3 years ago)
Author:
johnbillion
Message:

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

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-includes/comment.php

    r35745 r36039  
    27512751        $comment_author_email = $user->user_email;
    27522752        $comment_author_url   = $user->user_url;
    2753         $user_id              = $user->ID;
     2753        $user_ID              = $user->ID;
    27542754        if ( current_user_can( 'unfiltered_html' ) ) {
    27552755            if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] )
     
    27882788        'comment_type',
    27892789        'comment_parent',
    2790         'user_id'
     2790        'user_ID'
    27912791    );
    27922792
  • branches/4.4/tests/phpunit/tests/comment-submission.php

    r35745 r36039  
    55 */
    66class Tests_Comment_Submission extends WP_UnitTestCase {
     7
     8    protected $preprocess_comment_data = array();
    79
    810    function setUp() {
     
    591593    }
    592594
     595    /**
     596     * @ticket 34997
     597     */
     598    public function test_comment_submission_sends_all_expected_parameters_to_preprocess_comment_filter() {
     599
     600        $user = self::factory()->user->create_and_get( array(
     601            'role' => 'author',
     602        ) );
     603        wp_set_current_user( $user->ID );
     604
     605        $post = self::factory()->post->create_and_get();
     606        $data = array(
     607            'comment_post_ID' => $post->ID,
     608            'comment'         => 'Comment',
     609        );
     610
     611        add_filter( 'preprocess_comment', array( $this, 'filter_preprocess_comment' ) );
     612
     613        $comment = wp_handle_comment_submission( $data );
     614
     615        remove_filter( 'preprocess_comment', array( $this, 'filter_preprocess_comment' ) );
     616
     617        $this->assertNotWPError( $comment );
     618        $this->assertEquals( array(
     619            'comment_post_ID'      => $post->ID,
     620            'comment_author'       => $user->display_name,
     621            'comment_author_email' => $user->user_email,
     622            'comment_author_url'   => $user->user_url,
     623            'comment_content'      => $data['comment'],
     624            'comment_type'         => '',
     625            'comment_parent'       => '0',
     626            'user_ID'              => $user->ID,
     627            'user_id'              => $user->ID,
     628        ), $this->preprocess_comment_data );
     629
     630    }
     631
     632    public function filter_preprocess_comment( $commentdata ) {
     633        $this->preprocess_comment_data = $commentdata;
     634        return $commentdata;
     635    }
     636
    593637}
Note: See TracChangeset for help on using the changeset viewer.