Make WordPress Core

Ticket #7956: 7956_while_fix.patch

File 7956_while_fix.patch, 1.1 KB (added by Viper007Bond, 17 years ago)

Fix while() loops + don't return int if any parent is deleted/unapproved

  • wp-includes/comment.php

     
    529529 * @return int|null Comment page number or null on error.
    530530 */
    531531function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null ) {
    532         if ( !$comment = get_comment( $comment_ID ) )
     532        $comment = get_comment( $comment_ID );
     533
     534        if ( !$comment || 1 != $comment->comment_approved )
    533535                return;
    534536
    535537        if ( !get_option('page_comments') )
     
    543545        if ( null === $threaded )
    544546                $threaded = get_option('thread_comments');
    545547
    546         // Find this comment's top level parent
    547         if ( $threaded ) {
    548                 while ( 0 != $comment->comment_parent )
     548        // Find this comment's top level parent if threading is enabled
     549        if ( $threaded && 0 != $comment->comment_parent ) {
     550                while ( 0 != $comment->comment_parent ) {
    549551                        $comment = get_comment( $comment->comment_parent );
     552                        if ( !$comment || 1 != $comment->comment_approved )
     553                                return;
     554                }
    550555        }
    551556
    552557        // Start going through the comments until we find what page number the above top level comment is on