WordPress.org

Make WordPress Core

Ticket #17928: 17928.patch

File 17928.patch, 2.7 KB (added by jakub.tyrcha, 4 years ago)
  • wp-includes/comment-template.php

     
    878878         * The url of the current comment author escaped for use in attributes. 
    879879         */ 
    880880        $comment_author_url = esc_url($commenter['comment_author_url']); 
    881  
    882         /** @todo Use API instead of SELECTs. */ 
    883         if ( $user_ID) { 
    884                 $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)); 
    885         } else if ( empty($comment_author) ) { 
    886                 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') ); 
    887         } else { 
    888                 $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)); 
     881         
     882        $comments = get_comments( array('post_id' => $post->ID, 'order' => 'ASC') ); 
     883        $comments_parents = array(); 
     884        foreach ( $comments as $k=>$comment ) { 
     885                if ( 1 == $comment->comment_approved ) 
     886                        continue; 
     887                         
     888                if ( $user_ID ) { 
     889                        if ( ( "0" == $comment->comment_approved ) && ( $user_ID == $comment->user_id ) ) 
     890                                continue; 
     891                } 
     892                else { 
     893                        if ( ( "0" == $comment->comment_approved ) && ( wp_specialchars_decode($comment_author,ENT_QUOTES) == $comment->comment_author ) && ( $comment_author_email == $comment->comment_author_email )) 
     894                                continue; 
     895                } 
     896                $comments_parents[ $comment->comment_ID ] = $comment->comment_parent; 
     897                unset($comments[$k]); 
    889898        } 
    890  
     899         
     900        function find_parents_route( &$comments_parents, $node ) { 
     901                if ( !isset($comments_parents[$node]) )  
     902                        return $node; 
     903                if ( $comments_parents[$node] == 0 ) 
     904                        $comments_parents[$node] = 0; 
     905                else if ( isset ( $comments_parents[$node] ) ) 
     906                        $comments_parents[$node] = find_parents_route( &$comments_parents, $comments_parents[$node]); 
     907                return $comments_parents[$node]; 
     908        } 
     909         
     910        foreach ( $comments_parents as $k=>$v ) { 
     911                find_parents_route( $comments_parents, $k ); 
     912        }        
     913         
     914        foreach ( $comments as $comment ) { 
     915                if ( array_key_exists ( $comment->comment_parent , $comments_parents ) ) { 
     916                                                                           $comment->comment_parent = $comments_parents[$comment->comment_parent]; 
     917                                                                           } 
     918        } 
     919                                  
    891920        // keep $comments for legacy's sake 
    892921        $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID ); 
    893922        $comments = &$wp_query->comments;