Media: Use consistent method for instantiating an attachment author object in Media Library.

Previously, attachments without an author could cause a PHP fatal error due to calling the `::exists()` method on a `false` value.

Follow-up to [49207].

Props antpb, carloscastilloadhoc, hellofromTonya, garrett-eclipse.
Merges [49979] to the 5.6 branch.
Fixes #52030.

git-svn-id: https://develop.svn.wordpress.org/branches/5.6@49995 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-01-21 12:20:05 +00:00
parent 43b6bec349
commit 902c6d5be0
2 changed files with 3 additions and 1 deletions

View File

@ -3288,10 +3288,11 @@ function attachment_submitbox_metadata() {
$att_url = wp_get_attachment_url( $attachment_id );
$author = get_userdata( $post->post_author );
$author = new WP_User( $post->post_author );
$uploaded_by_name = __( '(no author)' );
$uploaded_by_link = '';
if ( $author->exists() ) {
$uploaded_by_name = $author->display_name ? $author->display_name : $author->nickname;
$uploaded_by_link = get_edit_user_link( $author->ID );

View File

@ -3861,6 +3861,7 @@ function wp_prepare_attachment_for_js( $attachment ) {
);
$author = new WP_User( $attachment->post_author );
if ( $author->exists() ) {
$author_name = $author->display_name ? $author->display_name : $author->nickname;
$response['authorName'] = html_entity_decode( $author_name, ENT_QUOTES, get_bloginfo( 'charset' ) );