Skip to content

Cover: Avoid passing null as the featured image size - #81444

Merged
t-hamano merged 2 commits into
trunkfrom
fix/cover-featured-image-null-size
Aug 11, 2026
Merged

Cover: Avoid passing null as the featured image size#81444
t-hamano merged 2 commits into
trunkfrom
fix/cover-featured-image-null-size

Conversation

@t-hamano

@t-hamano t-hamano commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What?

The Cover block asks WordPress for the featured image using null as the image size. This PR passes 'full' instead, which is what the code already ends up using anyway.

This fixes the PHP 8.5 CI failures on trunk.

Why?

Passing null as an image size was never valid — get_the_post_thumbnail_url() expects a size name or a width/height array.

PHP 8.5 now deprecates using null as an array key, and a recent WordPress change — r63177 — made image_constrain_size_for_editor() do exactly that kind of lookup with whatever size it is handed. The previous code never reached the lookup; the new one does. So our invalid null started producing a deprecation notice, which PHPUnit reports as a test error:

Tests_Blocks_Render_Cover::test_gutenberg_render_block_core_cover
Using null as an array offset is deprecated, use an empty string instead

Whatever Core decides to do about r63177, passing null here is our bug, so this is worth fixing on its own.

How?

'full' was chosen over 'post-thumbnail' because it keeps the output identical — passing null today always resolves to the full-size image URL, and 'full' does the same.

The <img> branch just above already uses 'post-thumbnail' and is intentionally left alone — that one is a responsive image, not a CSS background.

Testing Instructions

The failing test Tests_Blocks_Render_Cover::test_gutenberg_render_block_core_cover already covers this path, so green CI is the main check.

To confirm nothing changed visually:

  1. Set a featured image on a post.
  2. Add a Cover block, enable Use featured image, and turn on Fixed background or Repeated background.
  3. Leave the image size unset in the sidebar.
  4. On the front end, inspect the background-image URL on .wp-block-cover__image-background. It should be the full-size image, the same as before this change.

Use of AI Tools

Claude Code was used to track down the cause of the CI failure and to draft this description. The one-line change and the choice of 'full' were reviewed and accepted by me.

The parallax/repeated branch passed `null` to `get_the_post_thumbnail_url()`
when the `sizeSlug` attribute is absent, explicitly defeating the function's
own `'post-thumbnail'` default. `$size` is documented as `string|int[]`, so
`null` was never a valid value.

`null` propagates down to `image_constrain_size_for_editor()`, which since
WordPress r63177 evaluates `$_wp_additional_image_sizes[ $size ]` through
`isset()`. On PHP 8.5 a null array offset is deprecated, which surfaces the
latent bug as a test error.

Use `'full'` rather than `'post-thumbnail'` so the rendered output is
unchanged: `image_get_intermediate_size()` bails out early on a falsy `$size`,
so the current code always resolves to the full-size URL.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Aug 11, 2026
Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Block] Cover Affects the Cover Block - used to display content laid over a background image labels Aug 11, 2026

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to have some test coverage here if we could, but given that this is blocking everything in trunk it's better to get a fix in place.

@aduth

aduth commented Aug 11, 2026

Copy link
Copy Markdown
Member

Would be good to have some test coverage here if we could,

Reconciling this with the claim in the PR description:

The failing test Tests_Blocks_Render_Cover::test_gutenberg_render_block_core_cover already covers this path, so green CI is the main check.

I guess this is true and validates the decision to use 'full', as we assert it explicitly:

$this->assertStringContainsString( wp_get_attachment_image_url( self::$attachment_id, 'full' ), $rendered );

It could be further improved with tests around sizeSlug existence which currently has no coverage, but not a blocker.

@t-hamano

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

This PR appears to be valid, as the unit tests are passing on PHP 8.5.
https://github.com/WordPress/gutenberg/actions/runs/31507399760/job/93833160761?pr=81444

@t-hamano
t-hamano marked this pull request as ready for review August 11, 2026 15:49
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano

Copy link
Copy Markdown
Contributor Author

I investigated the AI's analysis results.

Ideally, for consistency with the get_the_post_thumbnail line, the fallback size for get_the_post_thumbnail_url should be post-thumbnail. However, since null has effectively resolved to the full size until now, changing it to post-thumbnail might unintentionally reduce image resolution. For backward compatibility, it would be best to specify full for now.

@t-hamano

Copy link
Copy Markdown
Contributor Author

This PR needs to be backported because the same CI error is occurring on the wp/7.1 branch.

@t-hamano t-hamano added the Backport to WP 7.1 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Aug 11, 2026
@t-hamano
t-hamano merged commit ab730b2 into trunk Aug 11, 2026
60 checks passed
@t-hamano
t-hamano deleted the fix/cover-featured-image-null-size branch August 11, 2026 16:40
@github-actions github-actions Bot added this to the Gutenberg 23.8 milestone Aug 11, 2026
@github-actions github-actions Bot removed the Backport to WP 7.1 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Aug 11, 2026
gutenbergplugin pushed a commit that referenced this pull request Aug 11, 2026
* Cover: Avoid passing null as the featured image size

The parallax/repeated branch passed `null` to `get_the_post_thumbnail_url()`
when the `sizeSlug` attribute is absent, explicitly defeating the function's
own `'post-thumbnail'` default. `$size` is documented as `string|int[]`, so
`null` was never a valid value.

`null` propagates down to `image_constrain_size_for_editor()`, which since
WordPress r63177 evaluates `$_wp_additional_image_sizes[ $size ]` through
`isset()`. On PHP 8.5 a null array offset is deprecated, which surfaces the
latent bug as a test error.

Use `'full'` rather than `'post-thumbnail'` so the rendered output is
unchanged: `image_get_intermediate_size()` bails out early on a falsy `$size`,
so the current code always resolves to the full-size URL.

Co-Authored-By: Claude <noreply@anthropic.com>

* Cover: Add CHANGELOG entry

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
@github-actions github-actions Bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Aug 11, 2026
@github-actions

Copy link
Copy Markdown

I just cherry-picked this PR to the wp/7.1 branch to get it included in the next release: cdc13e2

pento pushed a commit to WordPress/wordpress-develop that referenced this pull request Aug 12, 2026
This updates the pinned commit hash of the Gutenberg repository from `ea285b45692aed6c4f95353671393402f97f0aa7` to `b9743a015526ac8fd79298fd4e96cf002cee333b`.

A full list of changes included in this commit can be found on GitHub: 
WordPress/gutenberg@ea285b4...b9743a0

- Style states: fix state deselection when selecting the already selected block (WordPress/gutenberg#81277)
- Global styles: render element styles set only inside a breakpoint (WordPress/gutenberg#81265)
- Style states: Fix phantom pseudo element style output (WordPress/gutenberg#81291)
- Docs: remove breakpoint-only element style example from global styles guide (WordPress/gutenberg#81308)
- theme.json schema: responsive states belong to blocks (WordPress/gutenberg#81253)
- theme.json schema: allow responsive states on block style variations (WordPress/gutenberg#81309)
- Render viewport state element styles in the editor (WordPress/gutenberg#81307) (WordPress/gutenberg#81311)
- Site Editor: Decode HTML entities in Identity fields (WordPress/gutenberg#81269) (WordPress/gutenberg#81320)
- Editor: Keep the canvas height stable while resizing the canvas (WordPress/gutenberg#81374)
- Playlist: Normalize Waveform Player configuration handling (WordPress/gutenberg#81375)
- Playlist: Improve audio conversion and track selection (WordPress/gutenberg#80926) (WordPress/gutenberg#81385)
- fix: order site identity changes predictably (WordPress/gutenberg#81283)
- Cover: Avoid passing null as the featured image size (WordPress/gutenberg#81444)
- components/Menu: Restore Modal focus return when menu items close (WordPress/gutenberg#81446)
- Notes: Fix text wrapping for long usernames in collaboration sidebar (WordPress/gutenberg#81406)
- Site Editor: Use inverted ThemeProvider seed for portaled UI (WordPress/gutenberg#81296)

Props wildworks.
See #65529.

git-svn-id: https://develop.svn.wordpress.org/branches/7.1@63209 602fd350-edb4-49c9-b593-d223f7449a82
shail-mehta pushed a commit that referenced this pull request Aug 12, 2026
* Cover: Avoid passing null as the featured image size

The parallax/repeated branch passed `null` to `get_the_post_thumbnail_url()`
when the `sizeSlug` attribute is absent, explicitly defeating the function's
own `'post-thumbnail'` default. `$size` is documented as `string|int[]`, so
`null` was never a valid value.

`null` propagates down to `image_constrain_size_for_editor()`, which since
WordPress r63177 evaluates `$_wp_additional_image_sizes[ $size ]` through
`isset()`. On PHP 8.5 a null array offset is deprecated, which surfaces the
latent bug as a test error.

Use `'full'` rather than `'post-thumbnail'` so the rendered output is
unchanged: `image_get_intermediate_size()` bails out early on a falsy `$size`,
so the current code always resolves to the full-size URL.

Co-Authored-By: Claude <noreply@anthropic.com>

* Cover: Add CHANGELOG entry

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Aug 12, 2026
This updates the pinned commit hash of the Gutenberg repository from `ea285b45692aed6c4f95353671393402f97f0aa7` to `b9743a015526ac8fd79298fd4e96cf002cee333b`.

A full list of changes included in this commit can be found on GitHub: 
WordPress/gutenberg@ea285b4...b9743a0

- Style states: fix state deselection when selecting the already selected block (WordPress/gutenberg#81277)
- Global styles: render element styles set only inside a breakpoint (WordPress/gutenberg#81265)
- Style states: Fix phantom pseudo element style output (WordPress/gutenberg#81291)
- Docs: remove breakpoint-only element style example from global styles guide (WordPress/gutenberg#81308)
- theme.json schema: responsive states belong to blocks (WordPress/gutenberg#81253)
- theme.json schema: allow responsive states on block style variations (WordPress/gutenberg#81309)
- Render viewport state element styles in the editor (WordPress/gutenberg#81307) (WordPress/gutenberg#81311)
- Site Editor: Decode HTML entities in Identity fields (WordPress/gutenberg#81269) (WordPress/gutenberg#81320)
- Editor: Keep the canvas height stable while resizing the canvas (WordPress/gutenberg#81374)
- Playlist: Normalize Waveform Player configuration handling (WordPress/gutenberg#81375)
- Playlist: Improve audio conversion and track selection (WordPress/gutenberg#80926) (WordPress/gutenberg#81385)
- fix: order site identity changes predictably (WordPress/gutenberg#81283)
- Cover: Avoid passing null as the featured image size (WordPress/gutenberg#81444)
- components/Menu: Restore Modal focus return when menu items close (WordPress/gutenberg#81446)
- Notes: Fix text wrapping for long usernames in collaboration sidebar (WordPress/gutenberg#81406)
- Site Editor: Use inverted ThemeProvider seed for portaled UI (WordPress/gutenberg#81296)

Props wildworks.
See #65529.
Built from https://develop.svn.wordpress.org/branches/7.1@63209


git-svn-id: http://core.svn.wordpress.org/branches/7.1@62402 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Block] Cover Affects the Cover Block - used to display content laid over a background image [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo