WP_Theme_JSON::get_block_style_variation_selector()
Generates a selector for a block style variation.
Method of the class: WP_Theme_JSON{}
No Hooks.
Return
String
. Block selector with block style variation selector added to it.
Usage
$result = WP_Theme_JSON::get_block_style_variation_selector( $variation_name, $block_selector );
- $variation_name(string) (required)
- Name of the block style variation.
- $block_selector(string) (required)
- CSS selector for the block.
Changelog
Since 6.5.0 | Introduced. |
WP_Theme_JSON::get_block_style_variation_selector() WP Theme JSON::get block style variation selector code WP 6.6.2
protected static function get_block_style_variation_selector( $variation_name, $block_selector ) { $variation_class = ".is-style-$variation_name"; if ( ! $block_selector ) { return $variation_class; } $limit = 1; $selector_parts = explode( ',', $block_selector ); $result = array(); foreach ( $selector_parts as $part ) { $result[] = preg_replace_callback( '/((?::\([^)]+\))?\s*)([^\s:]+)/', function ( $matches ) use ( $variation_class ) { return $matches[1] . $matches[2] . $variation_class; }, $part, $limit ); } return implode( ',', $result ); }