Allow get_comments_number() to officially accept $post or $post_id. Adds unit tests.

Props coffee2code, JanHenkG.
Fixes #26240.


git-svn-id: https://develop.svn.wordpress.org/trunk@28558 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2014-05-23 17:43:03 +00:00
parent d07954ea60
commit 1061a15eaf
2 changed files with 37 additions and 7 deletions

View File

@@ -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.