Title: WP_Theme_JSON_Resolver::inject_variations_from_block_styles_registry
Published: July 16, 2024
Last modified: August 20, 2026

---

# WP_Theme_JSON_Resolver::inject_variations_from_block_styles_registry( array $data ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#changelog)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Adds variations sourced from the block styles registry to the supplied theme.json
data.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#parameters)󠁿

 `$data`arrayrequired

Array following the theme.json specification.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#return)󠁿

 array Theme json data including shared block style variation definitions.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#source)󠁿

    ```php
    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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-theme-json-resolver.php#L988)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-theme-json-resolver.php#L988-L1016)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#related)󠁿

| Uses | Description | 
| [_wp_array_set()](https://developer.wordpress.org/reference/functions/_wp_array_set/)`wp-includes/functions.php` |

Sets an array in depth based on a path of keys.

  | 
| [WP_Block_Styles_Registry::get_instance()](https://developer.wordpress.org/reference/classes/wp_block_styles_registry/get_instance/)`wp-includes/class-wp-block-styles-registry.php` |

Utility method to retrieve the main instance of the class.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/inject_variations_from_block_styles_registry/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_theme_json_resolver%2Finject_variations_from_block_styles_registry%2F)
before being able to contribute a note or feedback.