Adds variations sourced from the block styles registry to the supplied theme.json data.
Parameters
$data
arrayrequired- Array following the theme.json specification.
Source
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;
}
Changelog
Version | Description |
---|---|
6.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.