Changeset 54211 for trunk/src/wp-includes/block-supports/elements.php
- Timestamp:
- 09/19/2022 08:12:02 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-supports/elements.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/elements.php
r53260 r54211 90 90 * 91 91 * @since 6.0.0 92 * @since 6.1.0 Implemented the style engine to generate CSS and classnames. 92 93 * @access private 93 94 * … … 98 99 */ 99 100 function wp_render_elements_support_styles( $pre_render, $block ) { 100 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); 101 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); 102 $element_block_styles = isset( $block['attrs']['style']['elements'] ) ? $block['attrs']['style']['elements'] : null; 103 104 /* 105 * For now we only care about link color. 106 */ 101 107 $skip_link_color_serialization = wp_should_skip_block_supports_serialization( $block_type, 'color', 'link' ); 108 102 109 if ( $skip_link_color_serialization ) { 103 110 return null; 104 111 } 112 $class_name = wp_get_elements_class_name( $block ); 113 $link_block_styles = isset( $element_block_styles['link'] ) ? $element_block_styles['link'] : null; 105 114 106 $link_color = null; 107 if ( ! empty( $block['attrs'] ) ) { 108 $link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null ); 109 } 110 111 /* 112 * For now we only care about link color. 113 * This code in the future when we have a public API 114 * should take advantage of WP_Theme_JSON::compute_style_properties 115 * and work for any element and style. 116 */ 117 if ( null === $link_color ) { 118 return null; 119 } 120 121 $class_name = wp_get_elements_class_name( $block ); 122 123 if ( strpos( $link_color, 'var:preset|color|' ) !== false ) { 124 // Get the name from the string and add proper styles. 125 $index_to_splice = strrpos( $link_color, '|' ) + 1; 126 $link_color_name = substr( $link_color, $index_to_splice ); 127 $link_color = "var(--wp--preset--color--$link_color_name)"; 128 } 129 $link_color_declaration = esc_html( safecss_filter_attr( "color: $link_color" ) ); 130 131 $style = ".$class_name a{" . $link_color_declaration . ';}'; 132 133 wp_enqueue_block_support_styles( $style ); 115 wp_style_engine_get_styles( 116 $link_block_styles, 117 array( 118 'selector' => ".$class_name a", 119 'context' => 'block-supports', 120 ) 121 ); 134 122 135 123 return null;
Note: See TracChangeset
for help on using the changeset viewer.