Changeset 52434 for trunk/src/wp-includes/block-supports/spacing.php
- Timestamp:
- 01/04/2022 05:37:25 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/spacing.php
r52302 r52434 96 96 } 97 97 98 /**99 * Renders the spacing gap support to the block wrapper, to ensure100 * that the CSS variable is rendered in all environments.101 *102 * @since 5.9.0103 * @access private104 *105 * @param string $block_content Rendered block content.106 * @param array $block Block object.107 * @return string Filtered block content.108 */109 function wp_render_spacing_gap_support( $block_content, $block ) {110 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );111 $has_gap_support = block_has_support( $block_type, array( 'spacing', 'blockGap' ), false );112 if ( ! $has_gap_support || ! isset( $block['attrs']['style']['spacing']['blockGap'] ) ) {113 return $block_content;114 }115 116 $gap_value = $block['attrs']['style']['spacing']['blockGap'];117 118 // Skip if gap value contains unsupported characters.119 // Regex for CSS value borrowed from `safecss_filter_attr`, and used here120 // because we only want to match against the value, not the CSS attribute.121 if ( preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ) {122 return $block_content;123 }124 125 $style = sprintf(126 '--wp--style--block-gap: %s',127 esc_attr( $gap_value )128 );129 130 // Attempt to update an existing style attribute on the wrapper element.131 $injected_style = preg_replace(132 '/^([^>.]+?)(' . preg_quote( 'style="', '/' ) . ')(?=.+?>)/',133 '$1$2' . $style . '; ',134 $block_content,135 1136 );137 138 // If there is no existing style attribute, add one to the wrapper element.139 if ( $injected_style === $block_content ) {140 $injected_style = preg_replace(141 '/<([a-zA-Z0-9]+)([ >])/',142 '<$1 style="' . $style . '"$2',143 $block_content,144 1145 );146 };147 148 return $injected_style;149 }150 151 98 // Register the block support. 152 99 WP_Block_Supports::get_instance()->register( … … 157 104 ) 158 105 ); 159 160 add_filter( 'render_block', 'wp_render_spacing_gap_support', 10, 2 );
Note: See TracChangeset
for help on using the changeset viewer.