wp_register_block_style_variations_from_theme_json_partials()
Registers block style variations read in from theme.json partials.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
null
. Nothing (null).
Usage
wp_register_block_style_variations_from_theme_json_partials( $variations );
- $variations(array) (required)
- Shared block style variations.
Changelog
Since 6.6.0 | Introduced. |
wp_register_block_style_variations_from_theme_json_partials() wp register block style variations from theme json partials code WP 6.8.1
function wp_register_block_style_variations_from_theme_json_partials( $variations ) { if ( empty( $variations ) ) { return; } $registry = WP_Block_Styles_Registry::get_instance(); foreach ( $variations as $variation ) { if ( empty( $variation['blockTypes'] ) || empty( $variation['styles'] ) ) { continue; } $variation_name = $variation['slug'] ?? _wp_to_kebab_case( $variation['title'] ); $variation_label = $variation['title'] ?? $variation_name; foreach ( $variation['blockTypes'] as $block_type ) { $registered_styles = $registry->get_registered_styles_for_block( $block_type ); // Register block style variation if it hasn't already been registered. if ( ! array_key_exists( $variation_name, $registered_styles ) ) { register_block_style( $block_type, array( 'name' => $variation_name, 'label' => $variation_label, ) ); } } } }