forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Modernization: Correct fallback return value in
get_the_author()
.
If the `$authordata` global is not set, `get_the_author()` returned `null`, causing a PHP 8.1 "null to non-nullable" deprecation notice in `ent2ncr()` hooked via `the_author` filter: {{{ str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated }}} This commit updates `get_the_author()` to return an empty string if called before `$authordata` is set, bringing consistency with a few other similar functions which also return an empty string in this case: * `get_the_author_meta()` * `get_the_author_posts_link()` * `get_the_modified_author()` Follow-up to [695/tests], [2858], [11138], [12284], [20575], [34677], [44616], [53187]. Props Soean, jrf, sabernhardt, salvoaranzulla, antpb, ebai4, sajjad67, tijmensmit, SergeyBiryukov. Fixes #58157. git-svn-id: https://develop.svn.wordpress.org/trunk@55755 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
02d89bc
commit fdd333f
Showing
5 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @group author | ||
* @group user | ||
* | ||
* @covers ::get_the_modified_author | ||
*/ | ||
class Tests_User_GetTheModifiedAuthor extends WP_UnitTestCase { | ||
protected static $author_id = 0; | ||
protected static $post_id = 0; | ||
|
||
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { | ||
self::$author_id = $factory->user->create( | ||
array( | ||
'role' => 'author', | ||
'user_login' => 'test_author', | ||
'display_name' => 'Test Author', | ||
'description' => 'test_author', | ||
'user_url' => 'http://example.com', | ||
) | ||
); | ||
|
||
self::$post_id = $factory->post->create( | ||
array( | ||
'post_author' => self::$author_id, | ||
'post_status' => 'publish', | ||
'post_content' => 'content', | ||
'post_title' => 'title', | ||
'post_type' => 'post', | ||
) | ||
); | ||
|
||
add_post_meta( self::$post_id, '_edit_last', self::$author_id ); | ||
} | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$GLOBALS['post'] = self::$post_id; | ||
} | ||
|
||
public function test_get_the_modified_author() { | ||
$author_name = get_the_modified_author(); | ||
$user = new WP_User( self::$author_id ); | ||
|
||
$this->assertSame( $user->display_name, $author_name ); | ||
$this->assertSame( 'Test Author', $author_name ); | ||
} | ||
|
||
/** | ||
* @ticket 58157 | ||
*/ | ||
public function test_get_the_modified_author_should_return_empty_string_if_user_id_does_not_exist() { | ||
update_post_meta( self::$post_id, '_edit_last', -1 ); | ||
|
||
$this->assertSame( '', get_the_modified_author() ); | ||
} | ||
} |