Skip to content

Fix undefined array key “id” warning in filter_image_block_render_block - #1321

Open
robertgray-topflight wants to merge 1 commit into
cloudinary:masterfrom
robertgray-topflight:patch-1
Open

robertgray-topflight wants to merge 1 commit into
cloudinary:masterfrom
robertgray-topflight:patch-1

Conversation

@robertgray-topflight

Copy link
Copy Markdown

Approach

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

  1. Add a core/image block that uses an external image URL and has overwrite_transformations set in its attributes, then view the page on PHP 8.2 or later with WP_DEBUG on.
  2. Before the change, the warning appears in the log for class-filter.php line 733. After the change, it does not.
  3. Confirm an image block from the media library with overwrite transformations still gets the cld-overwrite class.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant