Skip to content

Commit

Permalink
Update PHP implementation to check for layout support when rendering …
Browse files Browse the repository at this point in the history
…at the block level
  • Loading branch information
andrewserong committed Jul 1, 2022
1 parent c202f94 commit 0281707
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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 {
Expand Down

0 comments on commit 0281707

Please sign in to comment.