Skip to content

Commit c86d940

Browse files
Users: Correct get_the_author_posts() to always return an integer.
This matches the documented `@return` type. Follow-up to [5638], [13576], [36085], [60296]. Props justlevine. See #63268. git-svn-id: https://develop.svn.wordpress.org/trunk@60299 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6ae67d9 commit c86d940

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/wp-includes/author-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function get_the_author_posts() {
286286
if ( ! $post ) {
287287
return 0;
288288
}
289-
return count_user_posts( $post->post_author, $post->post_type );
289+
return (int) count_user_posts( $post->post_author, $post->post_type );
290290
}
291291

292292
/**

tests/phpunit/tests/user/getTheAuthorPosts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function test_get_the_author_posts() {
4242
// Test with no global post, result should be 0 because no author is found.
4343
$this->assertSame( 0, get_the_author_posts() );
4444
$GLOBALS['post'] = self::$post_id;
45-
$this->assertEquals( 1, get_the_author_posts() );
45+
$this->assertSame( 1, get_the_author_posts() );
4646
}
4747

4848
/**
@@ -60,7 +60,7 @@ public function test_get_the_author_posts_with_custom_post_type() {
6060
);
6161
$GLOBALS['post'] = $cpt_ids[0];
6262

63-
$this->assertEquals( 2, get_the_author_posts() );
63+
$this->assertSame( 2, get_the_author_posts() );
6464

6565
_unregister_post_type( 'wptests_pt' );
6666
}

0 commit comments

Comments
 (0)