Ticket #28603: 28603.2.diff
File 28603.2.diff, 5.1 KB (added by , 10 years ago) |
---|
-
src/wp-includes/comment.php
26 26 * 27 27 * @global wpdb $wpdb WordPress database abstraction object. 28 28 * 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. 37 38 * @return bool If all checks pass, true, otherwise false. 38 39 */ 39 function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {40 function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, $comment_type, $user_id = false ) { 40 41 global $wpdb; 41 42 42 43 // If manual moderation is enabled, skip all checks and return false. … … 110 111 */ 111 112 if ( 1 == get_option('comment_whitelist')) { 112 113 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 } 115 120 if ( ( 1 == $ok_to_comment ) && 116 ( empty( $mod_keys) || false === strpos( $email, $mod_keys) ) )121 ( empty( $mod_keys ) || false === strpos( $email, $mod_keys ) ) ) 117 122 return true; 118 123 else 119 124 return false; … … 1177 1182 $commentdata['comment_content'], 1178 1183 $commentdata['comment_author_IP'], 1179 1184 $commentdata['comment_agent'], 1180 $commentdata['comment_type'] 1185 $commentdata['comment_type'], 1186 ( ! empty( $commentdata['user_id'] ) ? $commentdata['user_id'] : false ) 1181 1187 ) ) { 1182 1188 $approved = 1; 1183 1189 } else { -
tests/phpunit/tests/comment/query.php
967 967 $this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found ); 968 968 } 969 969 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 970 992 public function test_search() { 971 993 $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' ) ); 972 994 $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' ) );