From d1389ca9850825cb5fecc67550cb387671167d6a Mon Sep 17 00:00:00 2001 From: robertgray-topflight Date: Thu, 15 Oct 2026 13:00:54 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20undefined=20array=20key=20=E2=80=9Cid?= =?UTF-8?q?=E2=80=9D=20warning=20in=20filter=5Fimage=5Fblock=5Frender=5Fbl?= =?UTF-8?q?ock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit filter_image_block_render_block reads $block[‘attrs’][‘id’] whenever a core/image block has overwrite_transformations set. If the block has no id attribute, for example an image block that points at a URL rather than a media library image, PHP logs “Undefined array key id” on every render. This adds a check that the id is not empty before the str_replace runs. Blocks with an id behave as before. QA notes Add a core/image block that uses an external image URL and has overwrite_transformations set in its attributes, and view the page on PHP 8.2 or later with WP_DEBUG on. Before the change, the warning appears in the log for class-filter.php line 733. After the change, it does not. Confirm an image block from the media library with overwrite transformations still gets the cld-overwrite class. --- php/media/class-filter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/media/class-filter.php b/php/media/class-filter.php index 8fe23347b..3a30aee35 100644 --- a/php/media/class-filter.php +++ b/php/media/class-filter.php @@ -729,7 +729,7 @@ public function catch_media_templates_maybe() { * @return string */ public function filter_image_block_render_block( $block_content, array $block ) { - if ( 'core/image' === $block['blockName'] && ! empty( $block['attrs']['overwrite_transformations'] ) ) { + if ( 'core/image' === $block['blockName'] && ! empty( $block['attrs']['overwrite_transformations'] ) && ! empty( $block['attrs']['id'] )) { $block_content = str_replace( 'wp-image-' . $block['attrs']['id'], 'wp-image-' . $block['attrs']['id'] . ' cld-overwrite', $block_content ); }