Make WordPress Core

Opened 2 months ago

Closed 2 months ago

#64499 closed defect (bug) (duplicate)

Undefined array key "file" in wp-includes/media.php

Reported by: djsuperfive's profile djsuperfive Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

Hi,

I have this error emitted by wp-includes/media.php

ErrorException thrown with message "Undefined array key "file""

Stacktrace:
#16 ErrorException in /.../cms/wp-includes/media.php:1789
#15 Themosis\Core\Bootstrap\ExceptionHandler:handleError in /.../cms/wp-includes/media.php:1789
#14 wp_image_add_srcset_and_sizes in /.../cms/wp-includes/media.php:2342
#13 wp_img_tag_add_srcset_and_sizes_attr in /.../cms/wp-includes/media.php:1954
#12 wp_filter_content_tags in /.../cms/wp-includes/class-wp-hook.php:341
#11 WP_Hook:apply_filters in /.../cms/wp-includes/plugin.php:205
#10 apply_filters in /.../cms/wp-includes/blocks/post-content.php:50
#9 render_block_core_post_content in /.../cms/wp-includes/class-wp-block.php:599
#8 WP_Block:render in /.../cms/wp-includes/class-wp-block.php:579
#7 WP_Block:render in /.../cms/wp-includes/class-wp-block.php:579
#6 WP_Block:render in /.../cms/wp-includes/blocks.php:2383
#5 render_block in /.../cms/wp-includes/blocks.php:2466
#4 do_blocks in /.../cms/wp-includes/block-template.php:291
#3 get_the_block_template_html in /.../cms/wp-includes/template-canvas.php:12
#2 include in /.../cms/wp-includes/template-loader.php:125
#1 require_once in /.../cms/wp-blog-header.php:19
#0 require in /.../index.php:11

I dumped the $image_media variable used in media.php:1789, and here's what I have:

array(6) { 
  ["dominant_color"]=> string(6) "846453" 
  ["has_transparency"]=> bool(false) 
  ["sources"]=> array(1) { 
    ["image/webp"]=> array(2) { 
      ["file"]=> string(80) "royaumont_concert-dichotomia-tactus-carmen-kleyken-carolina-santiago-scaled.webp" 
      ["filesize"]=> int(228474)
    }
  }
  ["width"]=> int(2560) 
  ["height"]=> int(1920) 
  ["sizes"]=> array(1) { 
    ["mosaic-carre"]=> array(5) { 
      ["file"]=> string(88) "royaumont_concert-dichotomia-tactus-carmen-kleyken-carolina-santiago-scaled-405x405.webp" 
      ["width"]=> int(405) 
      ["height"]=> int(405) 
      ["mime-type"]=> string(10) "image/webp" 
      ["cpt_last_cropping_data"]=> array(5) { 
        ["version"]=> int(2) 
        ["x"]=> int(449) 
        ["y"]=> int(0) 
        ["x2"]=> int(2560) 
        ["y2"]=> int(1920)
       }
     }
   }
}

Indeed there is no file key in the array.
I installed the Performance Lab plugin and its Modern Formats module to convert jpg images to webp.
I tried without any plugins and with the twentytwentyfive theme, same error.

Change History (2)

#1 @sabernhardt
2 months ago

  • Description modified (diff)

#2 @sabernhardt
2 months ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Severity changed from blocker to normal
  • Status changed from new to closed
  • Version 6.9 deleted

The missing "file" array key in wp_image_add_srcset_and_sizes() is already reported on #60480. I'll add that your image was WEBP, not a PDF. If you have anything more to add there, please join that discussion.

Note: See TracTickets for help on using tickets.