Gets the styles for blocks from the block.json file.
Source
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' => WP_Theme_JSON::LATEST_SCHEMA );
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'] ) &&
! isset( $config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] )
) {
/*
* 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 $theme_json Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) );
/*
* Backward compatibility for extenders returning a WP_Theme_JSON_Data
* compatible class that is not a WP_Theme_JSON_Data object.
*/
if ( $theme_json instanceof WP_Theme_JSON_Data ) {
static::$blocks = $theme_json->get_theme_json();
} else {
$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 $theme_json ) Filters the data provided by the blocks for global styles & settings.
Changelog
Version | Description |
---|---|
6.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.