[wp-trac] [WordPress Trac] #37608: Undefined index: extension in class-wp-image-editor.php
WordPress Trac
noreply at wordpress.org
Tue Aug 9 04:58:04 UTC 2016
#37608: Undefined index: extension in class-wp-image-editor.php
--------------------------+-----------------------------
Reporter: JaworskiMatt | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Under some circumstances, 3rd party plugins will cause the
WP_Image_Editor::generate_filename() to print a notice about a missing
"extension" index in the ''$info'' variable.
It's rather hard to reproduce, but definitely happens inside PeepSo AJAX
upload with some photos containing EXIF rotation information. It can also
be found by simply googling it, like on this website:
http://www.pasadenamusclecompany.com/tag/featured
Obviously it only happens with ''WP_DEBUG'' set to ''TRUE''.
The ''$info'' variable is created using PHP's very own ''pathinfo()'' like
this:
{{{
$info = pathinfo( $this->file );
$dir = $info['dirname'];
$ext = $info['extension'];
}}}
According to PHP documentation, the ''extension'' index can be missing
(not set) if the file does not have one.
http://php.net/manual/en/function.pathinfo.php
The code above will obviously generate a notice in such a scenario. An
easy way around this is NOT to assume the "extension" index is present,
for example like this:
{{{
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
}}}
As far as I can tell, there are no drawbacks to this approach.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37608>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list