From e8181b093423c8fef406743daa30e70bb404b597 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 23 May 2014 17:44:14 +0000 Subject: [PATCH] Allow `get_comments_number()` to officially accept `$post` or `$post_id`. Adds unit tests. Props coffee2code, JanHenkG. Fixes #26240. Built from https://develop.svn.wordpress.org/trunk@28558 git-svn-id: http://core.svn.wordpress.org/trunk@28384 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 18f3fdff4a..0c7f40981a 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -682,16 +682,13 @@ function comments_link( $deprecated = '', $deprecated_2 = '' ) { * @return int The number of comments a post has. */ function get_comments_number( $post_id = 0 ) { - $post_id = absint( $post_id ); + $post = get_post( $post_id ); - if ( !$post_id ) - $post_id = get_the_ID(); - - $post = get_post($post_id); - if ( ! isset($post->comment_count) ) + if ( ! isset( $post->comment_count ) ) { $count = 0; - else + } else { $count = $post->comment_count; + } /** * Filter the returned comment count for a post.