wordpress-develop icon indicating copy to clipboard operation
wordpress-develop copied to clipboard

Fix: Undefined Array Key in `wp_image_add_srcset_and_sizes` function

Open Debarghya-Banerjee opened this issue 1 year ago • 2 comments

Trac Ticket: Core-60480

Description

  • This pull request addresses a warning encountered during the media import process when using the "Download and import file attachments" option in the Tools > Import section of WordPress. A warning is triggered due to an attempt to access an undefined array key in the wp_image_add_srcset_and_sizes function.

Proposed Changes

  • Added an isset() check before accessing the 'file' key of the $image_meta array to prevent the warning from occurring.

  • This adjustment ensures that the code handles cases where media metadata retrieval fails more gracefully, avoiding the warning message.

  • Additionally, this change is aimed at bringing consistency across all functions that interact with attachment metadata, ensuring that similar checks are uniformly applied throughout the codebase.

Debarghya-Banerjee avatar Oct 30 '24 21:10 Debarghya-Banerjee