WP_Theme_JSON_Resolver::inject_variations_from_block_style_variation_files()
Adds variations sourced from block style variations files to the supplied theme.json data.
Метод класса: WP_Theme_JSON_Resolver{}
Хуков нет.
Возвращает
Массив
. Theme json data including shared block style variation definitions.
Использование
$result = WP_Theme_JSON_Resolver::inject_variations_from_block_style_variation_files( $data, $variations );
- $data(массив) (обязательный)
- Array following the theme.json specification.
- $variations(массив) (обязательный)
- Shared block style variations.
Список изменений
С версии 6.6.0 | Введена. |
Код WP_Theme_JSON_Resolver::inject_variations_from_block_style_variation_files() WP Theme JSON Resolver::inject variations from block style variation files WP 6.6.2
private static function inject_variations_from_block_style_variation_files( $data, $variations ) { if ( empty( $variations ) ) { return $data; } foreach ( $variations as $variation ) { if ( empty( $variation['styles'] ) || empty( $variation['blockTypes'] ) ) { continue; } $variation_name = $variation['slug'] ?? _wp_to_kebab_case( $variation['title'] ); foreach ( $variation['blockTypes'] as $block_type ) { // First, override partial styles with any top-level styles. $top_level_data = $data['styles']['variations'][ $variation_name ] ?? array(); if ( ! empty( $top_level_data ) ) { $variation['styles'] = array_replace_recursive( $variation['styles'], $top_level_data ); } // Then, override styles so far with any block-level styles. $block_level_data = $data['styles']['blocks'][ $block_type ]['variations'][ $variation_name ] ?? array(); if ( ! empty( $block_level_data ) ) { $variation['styles'] = array_replace_recursive( $variation['styles'], $block_level_data ); } $path = array( 'styles', 'blocks', $block_type, 'variations', $variation_name ); _wp_array_set( $data, $path, $variation['styles'] ); } } return $data; }