diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php
index dc63e36..afa9fd8 100644
|
|
function comments_link( $deprecated = '', $deprecated_2 = '' ) { |
835 | 835 | * @since 1.5.0 |
836 | 836 | * |
837 | 837 | * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post. |
838 | | * @return int The number of comments a post has. |
| 838 | * @return string The number of comments a post has. Numeric string is returned for compatibility reasons. |
839 | 839 | */ |
840 | 840 | function get_comments_number( $post_id = 0 ) { |
841 | 841 | $post = get_post( $post_id ); |
842 | 842 | |
843 | 843 | if ( ! $post ) { |
844 | | $count = 0; |
| 844 | $count = '0'; |
845 | 845 | } else { |
846 | 846 | $count = $post->comment_count; |
847 | 847 | $post_id = $post->ID; |
diff --git tests/phpunit/tests/comment/template.php tests/phpunit/tests/comment/template.php
index ce93be2..ab67b82 100644
|
|
class Tests_Comment_Template extends WP_UnitTestCase { |
17 | 17 | $this->assertEquals( 12, get_comments_number( get_post( $post_id ) ) ); |
18 | 18 | } |
19 | 19 | |
| 20 | function test_get_comments_number_return_type() { |
| 21 | $post_id = self::factory()->post->create(); |
| 22 | |
| 23 | $this->assertSame( '0', get_comments_number( 0 ) ); |
| 24 | $this->assertSame( '0', get_comments_number( $post_id ) ); |
| 25 | $this->assertSame( '0', get_comments_number( get_post( $post_id ) ) ); |
| 26 | |
| 27 | self::factory()->comment->create_post_comments( $post_id, 12 ); |
| 28 | |
| 29 | $this->assertSame( '12', get_comments_number( $post_id ) ); |
| 30 | $this->assertSame( '12', get_comments_number( get_post( $post_id ) ) ); |
| 31 | } |
| 32 | |
20 | 33 | function test_get_comments_number_without_arg() { |
21 | 34 | $post_id = self::factory()->post->create(); |
22 | 35 | $permalink = get_permalink( $post_id ); |