WP_Theme_JSON_Resolver::inject_variations_from_block_styles_registry
Adds variations sourced from the block styles registry to the supplied theme.json data.
Метод класса: WP_Theme_JSON_Resolver{}
Хуков нет.
Возвращает
array. Theme json data including shared block style variation definitions.
Использование
$result = WP_Theme_JSON_Resolver::inject_variations_from_block_styles_registry( $data );
- $data(массив) (обязательный)
- Array following the theme.json specification.
Список изменений
| С версии 6.6.0 | Введена. |
Код WP_Theme_JSON_Resolver::inject_variations_from_block_styles_registry() WP Theme JSON Resolver::inject variations from block styles registry WP 7.1.1
private static function inject_variations_from_block_styles_registry( $data ) {
$registry = WP_Block_Styles_Registry::get_instance();
$styles = $registry->get_all_registered();
foreach ( $styles as $block_type => $variations ) {
foreach ( $variations as $variation_name => $variation ) {
if ( empty( $variation['style_data'] ) ) {
continue;
}
// First, override registry styles with any top-level styles.
$top_level_data = $data['styles']['variations'][ $variation_name ] ?? array();
if ( ! empty( $top_level_data ) ) {
$variation['style_data'] = array_replace_recursive( $variation['style_data'], $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['style_data'] = array_replace_recursive( $variation['style_data'], $block_level_data );
}
$path = array( 'styles', 'blocks', $block_type, 'variations', $variation_name );
_wp_array_set( $data, $path, $variation['style_data'] );
}
}
return $data;
}