Repository navigation
Cover: Explicitly set isUserOverlayColor to false when media is updated - #65105
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +25 B (0%) Total Size: 1.78 MB
ℹ️ View Unchanged
|
Mamaduka
left a comment
There was a problem hiding this comment.
Thank you, @andrewserong! This fixes both issues 🎉
A tiny observation: When testing Cover blocks that were inserted before the fix, the overlay color stayed the same. I guess this is expected, since isUserOverlayColor: true and we have no way of knowing if it was set by a user or machine.
Cover Variations for testing
add_filter( 'get_block_type_variations', function( $variations, $block_type ) {
if ( 'core/cover' !== $block_type->name ) {
return $variations;
}
$variations[] = array(
'name' => 'cover-locked',
'title' => 'Cover Block Variation Locked',
'description' => 'Cover block variation with locked settings.',
'category' => 'media',
'icon' => 'smiley',
'scope' => array( 'inserter' ),
'active' => array( 'className' ),
'attributes' => array(
'templateLock' => 'contentOnly',
'useFeaturedImage' => true,
'dimRatio' => 0,
'backgroundType' => "image",
'overlayColor' => "",
'isUserOverlayColor' => true,
'contentPosition' => "center center",
'isDark' => false,
'className' => "is-cover-locked",
'tagName' => "div",
'textColor' => "white",
'layout' => array(
'type' => "constrained",
'contentSize' => ""
),
),
'innerBlocks' => array(
array(
'name' => 'core/heading',
'attributes' => array(
'level' => 1,
'placeholder' => "When reloading the page, the templateLock 'contentOnly' is lost.",
),
),
),
);
return $variations;
}, 10, 2 );|
Thanks for the review! Since this implements the approach that @ajlende recommended, I'll merge this in now. Happy to follow up on Monday if there's any further feedback, but I think this approach should work pretty well.
Yes, unfortunately that is a limitation of the approach here. But at least for newly added Cover blocks we'll have the correct behaviour now 🙂 |
Verify that isUserOverlayColor is explicitly set to false (not undefined) after uploading an image. This is the regression tested by PR #65105 — without the fix, subsequent image replacements would not auto-update the overlay color because the attribute was left as undefined rather than being explicitly false. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
What?
Fixes #64702, fixes #64480
Update the logic in the Cover block to explicitly set
isUserOverlayColortofalsewhen the media is changed. Also, update the deprecation that setsisUserOverlayColortotrueto only do so if the attribute is not already set.Between these two changes, the issue linked issues above should be resolved. The main goal of this PR is to ensure that the Cover block's auto overlay color behaviour (where an overlay color is set when an image is added) continues to work even after a post or page reload.
Kudos: @ajlende for the suggestion of this fix in #65077 (comment)
Why?
Ensure that the Cover block's auto overlay color behaviour continues to work after reloading the editor, if the user has never manually set the overlay color for the Cover block.
Prior to this change, the deprecation was firing too frequently. Because the deprecation didn't check to see if
isUserOverlayColorwas already set, it would fire even when it didn't need to. Additionally, without settingisUserOverlayColorexplicitly tofalse, the deprecation would run on Cover blocks where a user had never manually interacted with the overlay color.How?
isUserOverlayColortofalseif it isn't already set totrue.isUserOverlayColorto only do so if the attribute has never been set to a value at all (isundefined).Testing Instructions
Follow the reproduction steps in #64702. Basically:
Also, for extra testing, see that the sample code in #64480 works correctly with this PR applied.
Screenshots or screencast
This screengrab demos the auto color overlay holding up beyond reloading the post editor. It only sticks once a user sets an overlay color deliberatly:
cover-block.mp4