From 8d76dc5af1fd5e34b318887cc80ec8ac16361bb2 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 28 Oct 2008 07:17:29 +0000 Subject: [PATCH] get_page_of_comment() fixes from Viper007Bond. see #7956 git-svn-id: http://svn.automattic.com/wordpress/trunk@9377 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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 bf8b87c8b..f8a3c42c6 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