Skip to content

Commit

Permalink
Layout: Fix blockGap output when using a falsy 0 value (#43757)
Browse files Browse the repository at this point in the history
* Layout: Fix blockGap output when using a falsy 0 value

* Update flex layout output, too

* Add not null check for global styles, too
  • Loading branch information
andrewserong authored Sep 1, 2022
1 parent 2afc395 commit a12b882
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
if ( is_array( $gap_value ) ) {
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
}
if ( $gap_value && ! $should_skip_gap_serialization ) {
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
array_push(
$layout_styles,
array(
Expand Down Expand Up @@ -129,7 +129,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
if ( is_array( $gap_value ) ) {
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
}
if ( $gap_value && ! $should_skip_gap_serialization ) {
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
// Get spacing CSS variable from preset value if provided.
if ( is_string( $gap_value ) && str_contains( $gap_value, 'var:preset|spacing|' ) ) {
$index_to_splice = strrpos( $gap_value, '|' ) + 1;
Expand Down Expand Up @@ -198,7 +198,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
}
$gap_value = trim( $combined_gap_value );

if ( $gap_value && ! $should_skip_gap_serialization ) {
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
$layout_styles[] = array(
'selector' => $selector,
'declarations' => array( 'gap' => $gap_value ),
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ protected function get_layout_styles( $block_metadata ) {
}
}

if ( $block_gap_value ) {
if ( null !== $block_gap_value ) {
foreach ( $layout_definitions as $layout_definition_key => $layout_definition ) {
// Allow skipping default layout for themes that opt-in to block styles, but opt-out of blockGap.
if ( ! $has_block_gap_support && 'default' === $layout_definition_key ) {
Expand Down

0 comments on commit a12b882

Please sign in to comment.