From 489e47692a7dac3268795cf4578f6f5fe985ec2f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 18 Jan 2021 12:55:07 +0000 Subject: [PATCH] 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. Props antpb, carloscastilloadhoc, hellofromTonya, garrett-eclipse. Fixes #52030. Built from https://develop.svn.wordpress.org/trunk@49979 git-svn-id: http://core.svn.wordpress.org/trunk@49680 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/media.php | 3 ++- wp-includes/media.php | 1 + wp-includes/version.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index bd1cbeb037..8e929f38a7 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -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 ); diff --git a/wp-includes/media.php b/wp-includes/media.php index a22a1f359f..d29426213e 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -3929,6 +3929,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' ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 423b8bbdcd..7ab728cded 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49978'; +$wp_version = '5.7-alpha-49979'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.