Make WordPress Core

Ticket #10790: 10790.diff

File 10790.diff, 1.6 KB (added by solarissmoke, 14 years ago)
  • wp-includes/comment-template.php

     
    880880        $comment_author_url = esc_url($commenter['comment_author_url']);
    881881
    882882        /** @todo Use API instead of SELECTs. */
    883         if ( $user_ID) {
     883        if ( $user_ID ) {
    884884                $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date_gmt", $post->ID, $user_ID));
    885885        } else if ( empty($comment_author) ) {
    886                 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
     886                // attempt to sniff recent (within the last hour) anonymous comments from the current visitor
     887                $comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( comment_author = '' AND comment_approved = '0' AND comment_author_IP = %s AND comment_agent = %s AND comment_date_gmt > %s ) ) ORDER BY comment_date_gmt", $post->ID, $_SERVER['REMOTE_ADDR'], substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ), gmdate( 'Y-m-d H:i:s', time() - 3600 ) ) );   
    887888        } else {
    888889                $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
    889890        }