WordPress.org

Make WordPress Core

Ticket #7956: 7956_while_fix.2.patch

File 7956_while_fix.2.patch, 2.2 KB (added by Viper007Bond, 5 years ago)

Properly use get_comments() so it doesn't return the whole DB table + phpdocs

  • wp-includes/comment.php

     
    194194        else 
    195195                $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 
    196196 
    197         if ( 'ASC' != $order ) 
    198                 $order = 'DESC'; 
     197        $order = ( 'ASC' == $order ) ? 'ASC' : 'DESC'; 
    199198 
    200199        $orderby = 'comment_date_gmt';  // Hard code for now 
    201200 
     
    484483 * Calculate the total number of comment pages. 
    485484 * 
    486485 * @since 2.7.0 
     486 * @uses get_query_var() Used to fill in the default for $per_page parameter. 
     487 * @uses get_option() Used to fill in defaults for parameters. 
     488 * @uses Walker_Comment 
    487489 * 
    488490 * @param array $comments Optional array of comment objects.  Defaults to $wp_query->comments 
    489491 * @param int $per_page Optional comments per page. 
     
    523525 * Calculate what page number a comment will appear on for comment paging. 
    524526 * 
    525527 * @since 2.7.0 
     528 * @uses get_comment() Gets the full comment of the $comment_ID parameter. 
     529 * @uses get_option() Get various settings to control function and defaults. 
     530 * @uses get_page_of_comment() Used to loop up to top level comment. 
    526531 * 
    527532 * @param int $comment_ID Comment ID. 
    528533 * @param int $per_page Optional comments per page. 
     
    535540        if ( !get_option('page_comments') ) 
    536541                return 1; 
    537542 
    538         $comments = array_reverse( get_comments( $comment->comment_post_ID ) ); 
    539  
    540543        if ( null === $per_page ) 
    541544                $per_page = get_option('comments_per_page'); 
    542545 
    543546        if ( null === $threaded ) 
    544547                $threaded = get_option('thread_comments'); 
    545548 
    546         // Find this comment's top level parent 
    547         if ( $threaded ) { 
    548                 while ( 0 != $comment->comment_parent ) 
    549                         $comment = get_comment( $comment->comment_parent ); 
    550         } 
     549        // If threaded and this comment isn't top level, we need the page of the parent (this'll loop until top level) 
     550        if ( $threaded && 0 != $comment->comment_parent ) 
     551                return get_page_of_comment( $comment->comment_parent, $per_page, $threaded ); 
    551552 
     553        $comments = get_comments( array( 'post_id' => $comment->comment_post_ID, 'order' => 'ASC' ) ); 
     554 
    552555        // Start going through the comments until we find what page number the above top level comment is on 
    553556        $page = 1; 
    554557        $comthispage = 0;