wp_render_block_style_variation_class_name()
Ensure the variation block support class name generated and added to block attributes in the render_block_data gets applied to the block's markup.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Return
String
. Filtered block content.
Usage
wp_render_block_style_variation_class_name( $block_content, $block );
- $block_content(string) (required)
- Rendered block content.
- $block(array) (required)
- Block object.
Notes
Changelog
Since 6.6.0 | Introduced. |
wp_render_block_style_variation_class_name() wp render block style variation class name code WP 6.7.1
function wp_render_block_style_variation_class_name( $block_content, $block ) { if ( ! $block_content || empty( $block['attrs']['className'] ) ) { return $block_content; } /* * Matches a class prefixed by `is-style`, followed by the * variation slug, then `--`, and finally an instance number. */ preg_match( '/\bis-style-(\S+?--\d+)\b/', $block['attrs']['className'], $matches ); if ( empty( $matches ) ) { return $block_content; } $tags = new WP_HTML_Tag_Processor( $block_content ); if ( $tags->next_tag() ) { /* * Ensure the variation instance class name set in the * `render_block_data` filter is applied in markup. * See `wp_render_block_style_variation_support_styles`. */ $tags->add_class( $matches[0] ); } return $tags->get_updated_html(); }