WP_Theme_JSON_Resolver::get_block_data(): WP_Theme_JSON
Gets the styles for blocks from the block.json file.
Return
Source
File: wp-includes/class-wp-theme-json-resolver.php
.
View all references
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;
}
Hooks
-
apply_filters( 'wp_theme_json_data_blocks',
WP_Theme_JSON_Data ) -
Filters the data provided by the blocks for global styles & settings.
Changelog
Version | Description |
---|---|
6.1.0 | Introduced. |