WP_Theme_JSON::get_block_style_variation_feature_selector
Applies a block style variation class to a feature selector.
Feature selectors can target a different element than the block's root selector. For example, the Button block's root selector targets the inner link, while its dimensions width selector targets the outer wrapper. Apply the variation class directly to the selector that will receive the declarations instead of deriving it by subtracting the root selector from the feature selector.
Метод класса: WP_Theme_JSON{}
Хуков нет.
Возвращает
string. Feature selector with block style variation selector added.
Использование
$result = WP_Theme_JSON::get_block_style_variation_feature_selector( $style_variation, $feature_selector );
- $style_variation(массив) (обязательный)
- Style variation metadata.
- $feature_selector(строка) (обязательный)
- CSS selector for the feature.
Список изменений
| С версии 7.0.0 | Введена. |
Код WP_Theme_JSON::get_block_style_variation_feature_selector() WP Theme JSON::get block style variation feature selector WP 7.1.4
protected static function get_block_style_variation_feature_selector( $style_variation, $feature_selector ) {
$variation_path = $style_variation['path'] ?? array();
$variation_name = $style_variation['name'] ?? ( is_array( $variation_path ) ? end( $variation_path ) : null );
if ( ! $variation_name ) {
return $style_variation['selector'] ?? $feature_selector;
}
$variation_class = ".is-style-$variation_name";
$selector_parts = static::split_selector_list( $feature_selector );
$selector_parts = array_map(
static function ( $selector ) use ( $variation_class ) {
$prefix = $variation_class . ' ';
if ( str_starts_with( $selector, $prefix ) ) {
return substr( $selector, strlen( $prefix ) );
}
return $selector;
},
$selector_parts
);
return static::get_block_style_variation_selector(
$variation_name,
implode( ', ', $selector_parts )
);
}