WP_Theme_JSON::get_block_style_variation_selectorprotected staticWP 6.5.0

Generates a selector for a block style variation.

Метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

string. Block selector with block style variation selector added to it.

Использование

$result = WP_Theme_JSON::get_block_style_variation_selector( $variation_name, $block_selector );
$variation_name(строка) (обязательный)
Name of the block style variation.
$block_selector(строка) (обязательный)
CSS selector for the block.

Список изменений

С версии 6.5.0 Введена.

Код WP_Theme_JSON::get_block_style_variation_selector() WP 7.1.1

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 = static::split_selector_list( $block_selector );
	$result         = array();

	/*
	 * Append the variation class to each selector's ancestor: the first
	 * run of characters before any combinator (whitespace) or pseudo-class
	 * (`:`). Only the first match is replaced.
	 *
	 * Examples ("custom" variation):
	 * - `.wp-block`              => `.wp-block.is-style-custom`
	 * - `.wp-block .inner`       => `.wp-block.is-style-custom .inner`
	 * - `.wp-block:where(.a .b)` => `.wp-block.is-style-custom:where(.a .b)`
	 * - `:where(.outer .inner)`  => `:where(.outer.is-style-custom .inner)`
	 */
	foreach ( $selector_parts as $part ) {
		$result[] = preg_replace_callback(
			'/[^\s:]+/',
			function ( $matches ) use ( $variation_class ) {
				return $matches[0] . $variation_class;
			},
			$part,
			$limit
		);
	}

	return implode( ', ', $result );
}