Make WordPress Core

Ticket #28603: 28603.2.diff

File 28603.2.diff, 5.1 KB (added by voldemortensen, 10 years ago)
  • src/wp-includes/comment.php

     
    2626 *
    2727 * @global wpdb $wpdb WordPress database abstraction object.
    2828 *
    29  * @param string $author       Comment author name.
    30  * @param string $email        Comment author email.
    31  * @param string $url          Comment author URL.
    32  * @param string $comment      Content of the comment.
    33  * @param string $user_ip      Comment author IP address.
    34  * @param string $user_agent   Comment author User-Agent.
    35  * @param string $comment_type Comment type, either user-submitted comment,
    36  *                                     trackback, or pingback.
     29 * @param string                $author       Comment author name.
     30 * @param string                $email        Comment author email.
     31 * @param string                $url          Comment author URL.
     32 * @param string                $comment      Content of the comment.
     33 * @param string                $user_ip      Comment author IP address.
     34 * @param string                $user_agent   Comment author User-Agent.
     35 * @param string                $comment_type Comment type, either user-submitted comment,
     36 *                                                   trackback, or pingback.
     37 * @param bool|string Optional. $user_id      Comment author ID.
    3738 * @return bool If all checks pass, true, otherwise false.
    3839 */
    39 function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
     40function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type, $user_id = false ) {
    4041        global $wpdb;
    4142
    4243        // If manual moderation is enabled, skip all checks and return false.
     
    110111         */
    111112        if ( 1 == get_option('comment_whitelist')) {
    112113                if ( 'trackback' != $comment_type && 'pingback' != $comment_type && $author != '' && $email != '' ) {
    113                         // expected_slashed ($author, $email)
    114                         $ok_to_comment = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1");
     114                        if( false === $user_id ) {
     115                                // expected_slashed ($author, $email)
     116                                $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM " . $wpdb->comments . " WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 1", $author, $email ) );
     117                        } else {
     118                                $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM " . $wpdb->comments . " WHERE user_id = %s AND comment_approved = '1' LIMIT 1", $user_id ) );
     119                        }
    115120                        if ( ( 1 == $ok_to_comment ) &&
    116                                 ( empty($mod_keys) || false === strpos( $email, $mod_keys) ) )
     121                                ( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) )
    117122                                        return true;
    118123                        else
    119124                                return false;
     
    11771182                        $commentdata['comment_content'],
    11781183                        $commentdata['comment_author_IP'],
    11791184                        $commentdata['comment_agent'],
    1180                         $commentdata['comment_type']
     1185                        $commentdata['comment_type'],
     1186                        ( ! empty( $commentdata['user_id'] ) ? $commentdata['user_id'] : false )
    11811187                ) ) {
    11821188                        $approved = 1;
    11831189                } else {
  • tests/phpunit/tests/comment/query.php

     
    967967                $this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found );
    968968        }
    969969
     970        /**
     971         * @ticket 28603
     972         */
     973        public function test_comment_check_with_user_id_and_approved_comment() {
     974                // Make sure comment author has an approved comment.
     975                $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 4, 'comment_approved' => '1', 'comment_author' => 'foo', 'comment_author_email' => 'foo' ) );
     976                // Use check_comment to make sure comment is approved. Pass in $user_id
     977                $ret = check_comment( 'foo', 'foo@example.com', 'http://example.com', 'This is a comment.', '66.155.40.249', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0', 'comment', '4' );
     978                $this->assertTrue( $ret );
     979        }
     980
     981        /**
     982         * @ticket 28603
     983         */
     984        public function test_comment_check_with_user_id_and_no_approved_comment() {
     985                // Make sure comment author has no approved comments.
     986                $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
     987                // Use check_comment to make sure comment is held for moderation. Pass in $user_id
     988                $ret = check_comment( 'JukeboxHero', 'hero@jukebox.com', 'http://jukebox.com', 'Man, the show is sold out...', '66.155.40.249', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0', 'comment', $user_id );
     989                $this->assertFalse( $ret );
     990        }
     991
    970992        public function test_search() {
    971993                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => 'bar@example.com' ) );
    972994                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'bar', 'comment_author_email' => 'foo@example.com' ) );