From 45d0800e30b7e809a094c74345977664821d6f95 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 28 Oct 2008 07:17:29 +0000 Subject: [PATCH] get_page_of_comment() fixes from Viper007Bond. see #7956 git-svn-id: https://develop.svn.wordpress.org/trunk@9377 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index bf8b87c8be..f8a3c42c68 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -529,13 +529,15 @@ function get_comment_pages_count( $comments = null, $per_page = null, $threaded * @return int|null Comment page number or null on error. */ function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null ) { - if ( !$comment = get_comment( $comment_ID ) ) + $comment = get_comment( $comment_ID ); + + if ( !$comment || 1 != $comment->comment_approved ) return; if ( !get_option('page_comments') ) return 1; - $comments = array_reverse( get_comments( $comment->comment_post_ID ) ); + $comments = array_reverse( get_comments( array( 'post_id' => $comment->comment_post_ID ) ) ); if ( null === $per_page ) $per_page = get_option('comments_per_page'); @@ -543,10 +545,13 @@ function get_page_of_comment( $comment_ID, $per_page = null, $threaded = null ) if ( null === $threaded ) $threaded = get_option('thread_comments'); - // Find this comment's top level parent - if ( $threaded ) { - while ( 0 != $comment->comment_parent ) + // Find this comment's top level parent if threading is enabled + if ( $threaded && 0 != $comment->comment_parent ) { + while ( 0 != $comment->comment_parent ) { $comment = get_comment( $comment->comment_parent ); + if ( !$comment || 1 != $comment->comment_approved ) + return; + } } // Start going through the comments until we find what page number the above top level comment is on