-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Backporting block supports [border, color, elements, spacing] from Gutenberg to WP 6.1 #3204
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
Changes from 1 commit
ae4742d
ec6ea9d
9a01f76
5646544
d13204d
9f2682c
e7cafa8
20e5b59
fb597d3
bf978d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,7 @@ function wp_render_elements_support( $block_content, $block ) { | |
| * we want the descendant style to take priority, and this is done by loading it after, in DOM order. | ||
| * | ||
| * @since 6.0.0 | ||
| * @since 6.1.0 Using the style engine to generate CSS and classnames. | ||
| * @access private | ||
| * | ||
| * @param string|null $pre_render The pre-rendered content. Default null. | ||
|
|
@@ -97,40 +98,27 @@ function wp_render_elements_support( $block_content, $block ) { | |
| * @return null | ||
| */ | ||
| function wp_render_elements_support_styles( $pre_render, $block ) { | ||
| $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); | ||
| $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' ); | ||
| if ( $skip_link_color_serialization ) { | ||
| return null; | ||
| } | ||
|
|
||
| $link_color = null; | ||
| if ( ! empty( $block['attrs'] ) ) { | ||
| $link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null ); | ||
| } | ||
| $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); | ||
| $element_block_styles = isset( $block['attrs']['style']['elements'] ) ? $block['attrs']['style']['elements'] : null; | ||
|
|
||
| /* | ||
| * For now we only care about link color. | ||
| * This code in the future when we have a public API | ||
| * should take advantage of WP_Theme_JSON::compute_style_properties | ||
| * and work for any element and style. | ||
| */ | ||
| if ( null === $link_color ) { | ||
| return null; | ||
| } | ||
|
|
||
| $class_name = wp_get_elements_class_name( $block ); | ||
| $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' ); | ||
|
|
||
| if ( strpos( $link_color, 'var:preset|color|' ) !== false ) { | ||
| // Get the name from the string and add proper styles. | ||
| $index_to_splice = strrpos( $link_color, '|' ) + 1; | ||
| $link_color_name = substr( $link_color, $index_to_splice ); | ||
| $link_color = "var(--wp--preset--color--$link_color_name)"; | ||
| if ( $skip_link_color_serialization ) { | ||
| return null; | ||
| } | ||
| $link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) ); | ||
|
|
||
| $style = ".$class_name a{" . $link_color_declaration . ';}'; | ||
|
|
||
| wp_enqueue_block_support_styles( $style ); | ||
| $class_name = wp_get_elements_class_name( $block ); | ||
| $link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null; | ||
|
|
||
| wp_style_engine_get_styles( | ||
| $link_block_styles, | ||
| array( | ||
| 'selector' => ".$class_name a", | ||
| 'context' => 'block-supports', | ||
| ) | ||
| ); | ||
|
Comment on lines
+115
to
+121
Contributor
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. Don't we have to do something with the return value? 🤔
Contributor
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.
Contributor
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. Ah, looks like this needs #3273 in order for the relevant styling to be added!
Member
Author
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.
Not here since the style engine will register styles in a store using the context as key. Gutenberg fetches stored styles at render time and prints them out. |
||
|
|
||
| return null; | ||
| } | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.