In `get_the_author_posts()`, if there is no current `$post`, return `0` and bail.
Props krogsgard, aaroncampbell. Fixes #27998. git-svn-id: https://develop.svn.wordpress.org/trunk@28362 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8998c015b3
commit
b70967302b
|
@ -206,7 +206,11 @@ function the_author_link() {
|
|||
* @return int The number of posts by the author.
|
||||
*/
|
||||
function get_the_author_posts() {
|
||||
return count_user_posts( get_post()->post_author );
|
||||
$post = get_post();
|
||||
if ( ! $post ) {
|
||||
return 0;
|
||||
}
|
||||
return count_user_posts( $post->post_author );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -75,4 +75,11 @@ class Tests_User_Author extends WP_UnitTestCase {
|
|||
$this->assertEquals( '', get_the_author_meta( 'user_login' ) );
|
||||
$this->assertEquals( '', get_the_author_meta( 'does_not_exist' ) );
|
||||
}
|
||||
}
|
||||
|
||||
function test_get_the_author_posts() {
|
||||
// Test with no global post, result should be 0 because no author is found
|
||||
$this->assertEquals( 0, get_the_author_posts() );
|
||||
$GLOBALS['post'] = $this->post_id;
|
||||
$this->assertEquals( 1, get_the_author_posts() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue