Opened 4 years ago
Closed 4 years ago
#52030 closed defect (bug) (fixed)
Media metaboxes return fatal error if no author metadata present
Reported by: | carloscastilloadhoc | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.6.1 | Priority: | normal |
Severity: | normal | Version: | 5.6 |
Component: | Media | Keywords: | has-patch commit fixed-major |
Focuses: | Cc: |
Description
Images uploaded programatically to the media library via the wp_insert_attachment function won't have author metadata. This causes a fatal error in the metaboxes when you try to use the "edit media" option in the media library.
Specifically: Uncaught Error: Call to a member function exists() on bool in wp-admin/includes/media.php line 3295
This can be fixed for example by expanding the condition "if($author->exists())" with "if($author && $author->exists())".
While I haven't personally encountered them, this may cause additional errors in other places where the same check is performed (for example the wp_prepare_attachment_for_js function in wp-includes/media.php).
Thank you and kind regards.
Attachments (1)
Change History (11)
This ticket was mentioned in Slack in #core-media by hellofromtonya. View the logs.
4 years ago
#3
@
4 years ago
As noted above, the code in attachment_submitbox_metadata()
uses get_userdata()
:
$author = get_userdata( $post->post_author );
which indeed returns false
on failure.
However, the similar code in wp_prepare_attachment_for_js()
creates a new instance of WP_User
instead:
$author = new WP_User( $attachment->post_author );
Would be great to have some consistency here.
#4
@
4 years ago
- Keywords has-patch needs-testing added
Thanks @SergeyBiryukov , good call on consistency. I've uploaded an initial patch for us to work off of. @garrett-eclipse would really appreciate a review. Is there any other level of guard this needs? I assume since new WP_User()
it can't result in fatal.
#5
follow-up:
↓ 6
@
4 years ago
- Keywords commit added; needs-testing removed
Thanks for the catch @carloscastilloadhoc, the triage @hellofromTonya, the idea @SergeyBiryukov and the patch @antpb. It's looking and working good for me so am marking for commit. Carlos if you could confirm the change fixes your install that would also be appreciated.
#6
in reply to:
↑ 5
@
4 years ago
Replying to garrett-eclipse:
Thanks for the catch @carloscastilloadhoc, the triage @hellofromTonya, the idea @SergeyBiryukov and the patch @antpb. It's looking and working good for me so am marking for commit. Carlos if you could confirm the change fixes your install that would also be appreciated.
I do confirm the patch fixes the issue on my end, thanks.
#8
@
4 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 49979:
Hello @carloscastilloadhoc,
Welcome to WordPress Trac! Thank you for this ticket.
Introduced in #46866 and changeset [49207], a check is missing for
get_userdata()
as it returnsfalse
when no user is found. At a minimum, this code should be guarded. Moving this ticket into 5.6.1 to add this guard.For the case where an image is programmatically created without an assigned user, more discussions is needed. Pinging @antpb @garrett-eclipse for their thoughts.