Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Backport foundation for Layout block support refactor
  • Loading branch information
andrewserong committed Sep 12, 2022
commit e18b9ba1787a37d9d2e86fad346eb073aab94927
27 changes: 27 additions & 0 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
$block_classes['css'] = $actual_css;
$global_styles[] = $block_classes;
}
} else {
// If there is no `theme.json` file, ensure base layout styles are still available.
$block_classes = array(
'css' => 'base-layout-styles',
'__unstableType' => 'base-layout',
'isGlobalStyles' => true,
);
$actual_css = wp_get_global_stylesheet( array( $block_classes['css'] ) );
if ( '' !== $actual_css ) {
$block_classes['css'] = $actual_css;
$global_styles[] = $block_classes;
}
}

$editor_settings['styles'] = array_merge( $global_styles, get_block_editor_theme_styles() );
Expand Down Expand Up @@ -475,9 +487,24 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
$editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['padding'];
unset( $editor_settings['__experimentalFeatures']['spacing']['padding'] );
}
if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) {
$editor_settings['disableCustomSpacingSizes'] = ! $editor_ettings['__experimentalFeatures']['spacing']['customSpacingSize'];
unset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] );
}

if ( isset( $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) {
$spacing_sizes_by_origin = $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'];
$editor_settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ?
$spacing_sizes_by_origin['custom'] : (
isset( $spacing_sizes_by_origin['theme'] ) ?
$spacing_sizes_by_origin['theme'] :
$spacing_sizes_by_origin['default']
);
}

$editor_settings['__unstableResolvedAssets'] = _wp_get_iframed_editor_assets();
$editor_settings['localAutosaveInterval'] = 15;
$editor_settings['disableLayoutStyles'] = current_theme_supports( 'disable-layout-styles' );
$editor_settings['__experimentalDiscussionSettings'] = array(
'commentOrder' => get_option( 'comment_order' ),
'commentsPerPage' => get_option( 'comments_per_page' ),
Expand Down
50 changes: 50 additions & 0 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,54 @@ public static function get_theme_data( $deprecated = array(), $options = array()
return $with_theme_supports;
}

/**
* Gets the styles for blocks from the block.json file.
*
* @since 6.1.0
*
* @return WP_Theme_JSON
*/
public static function get_block_data() {
$registry = WP_Block_Type_Registry::get_instance();
$blocks = $registry->get_all_registered();
$config = array( 'version' => 1 );
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;
}
}

// Core here means it's the lower level part of the styles chain.
// It can be a core or a third-party block.
return new WP_Theme_JSON( $config, 'core' );
}

/**
* When given an array, this will remove any keys with the name `//`.
*
* @param array $array The array to filter.
* @return array The filtered array.
*/
private static function remove_JSON_comments( $array ) {
unset( $array['//'] );
foreach ( $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[ $k ] = static::remove_JSON_comments( $v );
}
}

return $array;
}

/**
* Returns the custom post type that contains the user's origin config
* for the active theme or a void array if none are found.
Expand Down Expand Up @@ -369,6 +417,7 @@ public static function get_user_data() {
* @since 5.8.0
* @since 5.9.0 Added user data, removed the `$settings` parameter,
* added the `$origin` parameter.
* @since 6.1.0 Added block data.
*
* @param string $origin Optional. To what level should we merge data.
* Valid values are 'theme' or 'custom'. Default 'custom'.
Expand All @@ -381,6 +430,7 @@ public static function get_merged_data( $origin = 'custom' ) {

$result = new WP_Theme_JSON();
$result->merge( static::get_core_data() );
$result->merge( static::get_block_data() );
$result->merge( static::get_theme_data() );

if ( 'custom' === $origin ) {
Expand Down
Loading