Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
634aa61
lib/class-wp-duotone-gutenberg.php
aristath May 31, 2023
393ff4a
lib/block-supports/border.php
aristath May 31, 2023
a047545
lib/class-wp-theme-json-resolver-gutenberg.php
aristath May 31, 2023
ce96d3b
lib/class-wp-theme-json-gutenberg.php
aristath May 31, 2023
0bb4d31
lib/block-supports/colors.php
aristath May 31, 2023
d0a4ef0
lib/block-supports/dimensions.php
aristath May 31, 2023
69ee300
bugfix in colors.php
aristath May 31, 2023
73d9f60
fix condition in colors.php
aristath May 31, 2023
a68c19c
lib/block-supports/layout.php
aristath May 31, 2023
3b637e4
lib/block-supports/position.php
aristath May 31, 2023
0e0d2cc
lib/block-supports/settings.php
aristath May 31, 2023
3ab4342
lib/block-supports/spacing.php
aristath May 31, 2023
98ccc2f
lib/block-supports/typography.php
aristath May 31, 2023
2794b0c
Revert "lib/block-supports/settings.php"
aristath May 31, 2023
6a18165
lib/block-supports/settings.php
aristath May 31, 2023
236b6ac
packages/block-library/src/gallery/index.php
aristath May 31, 2023
95949a9
packages/block-library/src/navigation/index.php
aristath May 31, 2023
e0bd282
packages/block-library/src/post-featured-image/index.php
aristath May 31, 2023
2e0cc17
packages/block-library/src/search/index.php
aristath May 31, 2023
d9276fb
packages/style-engine/docs/using-the-style-engine-with-block-supports.md
aristath May 31, 2023
998cb62
further improvements
aristath Jun 23, 2023
b508d1b
typo fix
aristath Jun 23, 2023
f993083
rebase conflict typo fix
aristath Jul 25, 2023
af87ace
Coding standards fix
aristath Jul 25, 2023
bcf4c02
resolve rebase conflicts & refactor
aristath Sep 12, 2023
bd252b4
logic fix
aristath Sep 12, 2023
6634c75
some sugar
aristath Sep 12, 2023
9366fe8
don't use null-coallescing yet (php 7.4+ only)
aristath Sep 12, 2023
5e7dc5a
Revert "don't use null-coallescing yet (php 7.4+ only)"
aristath Sep 12, 2023
a031125
bugfix
aristath Sep 12, 2023
8e31cb9
resolve rebase conflict
aristath Sep 14, 2023
f9ff2b5
readability improvement/simplification
aristath Sep 19, 2023
aa7ec19
missed this one in my previous commit
aristath Sep 19, 2023
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
Prev Previous commit
Next Next commit
lib/class-wp-theme-json-gutenberg.php
  • Loading branch information
aristath committed Sep 19, 2023
commit ce96d3b58652c3ef9452d75c7c80f0239c89a935
47 changes: 33 additions & 14 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -928,11 +928,14 @@ protected static function get_blocks_metadata() {

// Keep backwards compatibility for support.color.__experimentalDuotone.
if ( null === $duotone_selector ) {
$duotone_support = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null );
$duotone_support = isset( $block_type->supports['color']['__experimentalDuotone'] );

if ( $duotone_support ) {
$root_selector = wp_get_block_css_selector( $block_type );
$duotone_selector = WP_Theme_JSON_Gutenberg::scope_selector( $root_selector, $duotone_support );
$duotone_selector = WP_Theme_JSON_Gutenberg::scope_selector(
$root_selector,
_wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null )
);
}
}

Expand Down Expand Up @@ -1161,12 +1164,17 @@ protected function process_blocks_custom_css( $css, $selector ) {
*/
public function get_custom_css() {
// Add the global styles root CSS.
$stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' );
$stylesheet = isset( $this->theme_json['styles']['css'] )
? _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' )
: '';

// Add the global styles block CSS.
if ( isset( $this->theme_json['styles']['blocks'] ) ) {
foreach ( $this->theme_json['styles']['blocks'] as $name => $node ) {
$custom_block_css = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $name, 'css' ) );
$custom_block_css = isset( $this->theme_json['styles']['blocks'][ $name ]['css'] )
? _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $name, 'css' ) )
: '';

if ( $custom_block_css ) {
$selector = static::$blocks_metadata[ $name ]['selector'];
$stylesheet .= $this->process_blocks_custom_css( $custom_block_css, $selector );
Expand Down Expand Up @@ -1284,7 +1292,7 @@ protected function get_layout_styles( $block_metadata ) {
}

$selector = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : '';
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
$has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] );
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$layout_definitions = gutenberg_get_layout_definitions();
Expand All @@ -1297,7 +1305,9 @@ protected function get_layout_styles( $block_metadata ) {
// Use a fallback gap value if block gap support is not available.
if ( ! $has_block_gap_support ) {
$block_gap_value = static::ROOT_BLOCK_SELECTOR === $selector ? '0.5em' : null;
if ( ! empty( $block_type ) ) {
if ( ! empty( $block_type )
&& isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
) {
$block_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), null );
}
} else {
Expand Down Expand Up @@ -1814,7 +1824,9 @@ protected static function compute_preset_vars( $settings, $origins ) {
*/
protected static function compute_theme_vars( $settings ) {
$declarations = array();
$custom_values = _wp_array_get( $settings, array( 'custom' ), array() );
$custom_values = isset( $settings['custom'] )
? _wp_array_get( $settings, array( 'custom' ), array() )
: array();
$css_vars = static::flatten_tree( $custom_values );
foreach ( $css_vars as $key => $value ) {
$declarations[] = array(
Expand Down Expand Up @@ -2326,7 +2338,9 @@ public function get_styles_for_block( $block_metadata ) {
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
$selector = $block_metadata['selector'];
$settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
$settings = isset( $this->theme_json['settings'] )
? _wp_array_get( $this->theme_json, array( 'settings' ) )
: array();

$feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node );

Expand Down Expand Up @@ -2479,7 +2493,7 @@ static function ( $pseudo_selector ) use ( $selector ) {
*/
public function get_root_layout_rules( $selector, $block_metadata ) {
$css = '';
$settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
$settings = isset( $this->theme_json['settings'] ) ? _wp_array_get( $this->theme_json, array( 'settings' ) ) : array();
$use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];

/*
Expand Down Expand Up @@ -2528,9 +2542,10 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
$css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';

$block_gap_value = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' );
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
if ( $has_block_gap_support ) {
$block_gap_value = isset( $this->theme_json['styles']['spacing']['blockGap'] )
? _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' )
: '0.5em';
if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) {
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
$css .= ":where(.wp-site-blocks) > * { margin-block-start: $block_gap_value; margin-block-end: 0; }";
$css .= ':where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }';
Expand Down Expand Up @@ -3360,7 +3375,9 @@ public function get_data() {
* @return null|void
*/
public function set_spacing_sizes() {
$spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() );
$spacing_scale = isset( $this->theme_json['settings']['spacing']['spacingScale'] )
? _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() )
: array();

// Gutenberg didn't have the 1st isset check.
if ( ! isset( $spacing_scale['steps'] )
Expand Down Expand Up @@ -3546,7 +3563,9 @@ protected function get_feature_declarations_for_node( $metadata, &$node ) {
return $declarations;
}

$settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
$settings = isset( $this->theme_json['settings'] )
? _wp_array_get( $this->theme_json, array( 'settings' ) )
: array();

foreach ( $metadata['selectors'] as $feature => $feature_selectors ) {
// Skip if this is the block's root selector or the block doesn't
Expand Down