WP_Theme_JSON_Resolver::inject_variations_from_block_styles_registry( array $data ): array

In this article

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

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

Parameters

$dataarrayrequired
Array following the theme.json specification.

Return

array Theme json data including shared block style variation definitions.

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

VersionDescription
6.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.