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 Jun 30, 2022
1 parent 1ca3973 commit 94dd879
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 @@ -910,7 +910,16 @@ protected static function get_property_value( $styles, $path, $theme_json = null
* @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 @@ -926,8 +935,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 94dd879

Please sign in to comment.