-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cover: Explicitly set isUserOverlayColor to false when media is updated #65105
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🙂 |
What?
Fixes #64702, fixes #64480
Update the logic in the Cover block to explicitly set
isUserOverlayColor
tofalse
when the media is changed. Also, update the deprecation that setsisUserOverlayColor
totrue
to 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
isUserOverlayColor
was already set, it would fire even when it didn't need to. Additionally, without settingisUserOverlayColor
explicitly tofalse
, the deprecation would run on Cover blocks where a user had never manually interacted with the overlay color.How?
isUserOverlayColor
tofalse
if it isn't already set totrue
.isUserOverlayColor
to 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