-
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: Merge block and global styles #49434
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,18 +47,14 @@ function render_block_core_cover( $attributes, $content ) { | |||||||||||||||||||
} | ||||||||||||||||||||
$current_featured_image = get_the_post_thumbnail_url(); | ||||||||||||||||||||
|
||||||||||||||||||||
$styles = 'background-image:url(' . esc_url( $current_featured_image ) . '); '; | ||||||||||||||||||||
|
||||||||||||||||||||
if ( isset( $attributes['minHeight'] ) ) { | ||||||||||||||||||||
$height_unit = empty( $attributes['minHeightUnit'] ) ? 'px' : $attributes['minHeightUnit']; | ||||||||||||||||||||
$height = " min-height:{$attributes['minHeight']}{$height_unit}"; | ||||||||||||||||||||
|
||||||||||||||||||||
$styles .= $height; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
$processor = new WP_HTML_Tag_Processor( $content ); | ||||||||||||||||||||
$processor->next_tag(); | ||||||||||||||||||||
$processor->set_attribute( 'style', $styles ); | ||||||||||||||||||||
|
||||||||||||||||||||
$styles = $processor->get_attribute( 'style' ); | ||||||||||||||||||||
$merged_styles = ! empty( $styles ) ? $styles . ';' : ''; | ||||||||||||||||||||
$merged_styles .= 'background-image:url(' . esc_url( $current_featured_image ) . ');'; | ||||||||||||||||||||
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Maybe this should be done as a follow-up PR, but how about preventing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Let's do this in a follow-up 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, there's no need for that. You can't enabled a fixed background if if the featured image isn't set. So this code is never executed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the following steps could happen:
After this procedure, the media settings will not appear in the cover block, but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Never trust the user 😄 I've changed on a local branch and will push it shortly. |
||||||||||||||||||||
|
||||||||||||||||||||
$processor->set_attribute( 'style', $merged_styles ); | ||||||||||||||||||||
$content = $processor->get_updated_html(); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
|
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.
The
min-height
is already serialized in the content. So there's no need to add it separately now that thestyle
attribute values are merged.P.S. We might implement this via the
dimensions
support flag. See #45300.