#52145 closed defect (bug) (duplicate)
Prevent exception when no author
Reported by: | shaunjeffrey | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.7 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
An additional check for when $author is false should be added to wp-admin/includes/media.php:3291
in order to prevent an exception from being thrown.
One example is when images are added to the media library via an import script. If the author is not defined, then an exception will be thrown when attempting to edit the media post, as you cannot call the method exists on a non-object.
The easiest way to get around this issue is to simply check to ensure that $author is not empty.
# wp-admin/includes/media.php:3291 - Change the conditional to include a check for $author.
if ( $author && $author->exists() ) {
https://github.com/shaunjc/WordPress/commit/d939e85767f51f4b13c4ae7c6385d57ce8ab6fa9
https://github.com/WordPress/WordPress/pull/507
Change History (4)
This ticket was mentioned in PR #834 on WordPress/wordpress-develop by shaunjc.
4 years ago
#1
- Keywords has-patch added
#2
@
4 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Hi there, welcome to WordPress Trac!
Thanks for the report, we're already tracking this issue in #52030.
#3
@
4 years ago
Hi Sergey, that's good to know because I couldn't find any other tickets.
I'm a little surprised that the issue wasn't picked up by the automated tests two months ago when the change to the wp-admin/includes/media.php
file were made.
The solution is ridiculously simple, so hopefully it doesn't take too long to be implemented.
TimothyBJacobs commented on PR #834:
4 years ago
#4
Closing as the associated ticket has been closed as a dupe of https://core.trac.wordpress.org/ticket/52030 which has a patch.
Additional check for when $author is false to prevent an exception from being thrown.
One example is when images are added to the media library via an import script. If the author is not defined, then an exception will be thrown when attempting to edit the media post, as you cannot call the method exists on a non-object.
The easiest way to get around this issue is to simply check to ensure that $author is not empty.
Trac ticket: https://core.trac.wordpress.org/ticket/52145