[wp-trac] [WordPress Trac] #60480: Warning: Undefined array key "file" in .../wp-includes/media.php on line 1723

WordPress Trac noreply at wordpress.org
Fri Feb 9 01:05:19 UTC 2024


#60480: Warning: Undefined array key "file" in .../wp-includes/media.php on line
1723
--------------------------+-----------------------------
 Reporter:  shanemac10    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Import        |    Version:  6.4.3
 Severity:  major         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When running Tools > Import > Run Importer, then selecting "Download and
 import file attachments" on the import options, the media (what appears to
 be a native Featured Image in my case) does not import, and displays this
 following message for each failed media import:
 {{{
 Warning: Undefined array key "file" in .../wp-includes/media.php on line
 1723
 }}}


 When looking into the matter, it appears in
 **wp_img_tag_add_srcset_and_sizes_attr** on line 2154 and 2155 where
 **wp_get_attachment_metadata** is called, which may return false, then
 it's sent directly into **wp_image_add_srcset_and_sizes**, where it (on
 1723) tests a **preg_match** on it without testing if **$image_meta** is
 an array or if **key_exists**, etc.

 {{{
 2154  $image_meta = wp_get_attachment_metadata( $attachment_id ); // <---
 returns array|false
 2155  return wp_image_add_srcset_and_sizes( $image, $image_meta,
 $attachment_id );
 }}}

 {{{
 1723  if ( preg_match( '/-e[0-9]{13}/', $image_meta['file'],
 $img_edit_hash ) // <--- $image_meta may be false
 }}}

 Get blame says this code has been around for over 4 years.
 [https://github.com/WordPress/wordpress-develop/blame/6.4/src/wp-
 includes/media.php#L2138-L2159]

 My scenario is importing a custom post type (that is identical to generic
 post type) with only WYSIWYG content and a featured image, to a local dev
 site on my personal computer from a public site (w/ full DNS with SSL
 cert), so there should not be an issue with fetching the images I believe.
 Either way, this error is a bug, and needs a way to fail more gracefully
 if the issue is else where in the Import process.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60480>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list