From 0281707fdfe0f3078ac9ac75e611b7b1234c23e2 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 30 Jun 2022 11:58:25 +1000 Subject: [PATCH] Update PHP implementation to check for layout support when rendering at the block level --- .../wordpress-6.1/class-wp-theme-json-6-1.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php index 5e915a0dbde3a..eb3cfd38f48c4 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php @@ -1131,7 +1131,16 @@ public function set_spacing_sizes() { * @return string Layout styles for the block. */ protected function get_layout_styles( $block_metadata ) { - $block_rules = ''; + $block_rules = ''; + $block_type = null; + + if ( isset( $block_metadata['name'] ) ) { + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_metadata['name'] ); + if ( ! block_has_support( $block_type, array( '__experimentalLayout' ), false ) ) { + return $block_rules; + } + } + $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_styles_support = current_theme_supports( 'wp-block-styles' ); @@ -1147,8 +1156,7 @@ 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 = '0.5em'; - if ( isset( $block_metadata['name'] ) ) { - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_metadata['name'] ); + if ( ! empty( $block_type ) ) { $block_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' ); } } else {