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
This commit is contained in:
Scott Taylor 2014-05-23 17:44:14 +00:00
parent 03410a4067
commit e8181b0934
1 changed files with 4 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.