WP_Theme_JSON_Resolver::get_block_data()public staticWP 6.1.0

Gets the styles for blocks from the block.json file.

Method of the class: WP_Theme_JSON_Resolver{}

Hooks from the method

Return

WP_Theme_JSON.

Usage

$result = WP_Theme_JSON_Resolver::get_block_data();

Changelog

Since 6.1.0 Introduced.

WP_Theme_JSON_Resolver::get_block_data() code WP 6.1.1

public static function get_block_data() {
	$registry = WP_Block_Type_Registry::get_instance();
	$blocks   = $registry->get_all_registered();

	if ( null !== static::$blocks && static::has_same_registered_blocks( 'blocks' ) ) {
		return static::$blocks;
	}

	$config = array( 'version' => 2 );
	foreach ( $blocks as $block_name => $block_type ) {
		if ( isset( $block_type->supports['__experimentalStyle'] ) ) {
			$config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] );
		}

		if (
			isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) &&
			null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null )
		) {
			// Ensure an empty placeholder value exists for the block, if it provides a default blockGap value.
			// The real blockGap value to be used will be determined when the styles are rendered for output.
			$config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] = null;
		}
	}

	/**
	 * Filters the data provided by the blocks for global styles & settings.
	 *
	 * @since 6.1.0
	 *
	 * @param WP_Theme_JSON_Data Class to access and update the underlying data.
	 */
	$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) );
	$config     = $theme_json->get_data();

	static::$blocks = new WP_Theme_JSON( $config, 'blocks' );
	return static::$blocks;
}