| @@ -56,9 +56,9 @@ | ||
| 56 | 56 | return $attributes; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $dimensions_block_styles = array(); |
| 60 | - $supported_features = array( 'minHeight', 'height', 'width' ); | |
| 60 | + $supported_features = array( 'minHeight', 'minWidth', 'height', 'width' ); | |
| 61 | 61 | |
| 62 | 62 | foreach ( $supported_features as $feature ) { |
| 63 | 63 | $has_support = block_has_support( $block_type, array( 'dimensions', $feature ), false ); |
| 64 | 64 | $skip_serialization = wp_should_skip_block_supports_serialization( $block_type, 'dimensions', $feature ); |
| @@ -79,15 +79,31 @@ | ||
| 79 | 79 | return $attributes; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | + * Checks whether an aspectRatio block-support value is explicitly set. | |
| 84 | + * | |
| 85 | + * @param mixed $aspect_ratio Aspect-ratio value. | |
| 86 | + * @return bool Whether the value is an explicit aspect ratio. | |
| 87 | + */ | |
| 88 | +function gutenberg_is_explicit_aspect_ratio_value( $aspect_ratio ) { | |
| 89 | + if ( ! is_string( $aspect_ratio ) && ! is_numeric( $aspect_ratio ) ) { | |
| 90 | + return false; | |
| 91 | + } | |
| 92 | + | |
| 93 | + $aspect_ratio = strtolower( trim( (string) $aspect_ratio ) ); | |
| 94 | + | |
| 95 | + return '' !== $aspect_ratio && 'auto' !== $aspect_ratio; | |
| 96 | +} | |
| 97 | + | |
| 98 | +/** | |
| 83 | 99 | * Renders server-side dimensions styles to the block wrapper. |
| 84 | 100 | * This block support uses the `render_block` hook to ensure that |
| 85 | 101 | * it is also applied to non-server-rendered blocks. |
| 86 | 102 | * |
| 87 | - * @param string $block_content Rendered block content. | |
| 88 | - * @param array $block Block object. | |
| 89 | - * @return string Filtered block content. | |
| 103 | + * @param string $block_content Rendered block content. | |
| 104 | + * @param array $block Block object. | |
| 105 | + * @return string Filtered block content. | |
| 90 | 106 | */ |
| 91 | 107 | function gutenberg_render_dimensions_support( $block_content, $block ) { |
| 92 | 108 | $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); |
| 93 | 109 | $block_attributes = ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) ? $block['attrs'] : array(); |
| @@ -104,9 +120,9 @@ | ||
| 104 | 120 | $dimensions_block_styles['aspectRatio'] = $block_attributes['style']['dimensions']['aspectRatio'] ?? null; |
| 105 | 121 | |
| 106 | 122 | // To ensure the aspect ratio does not get overridden by `minHeight` or `height` unset any existing rule. |
| 107 | 123 | if ( |
| 108 | - isset( $dimensions_block_styles['aspectRatio'] ) | |
| 124 | + gutenberg_is_explicit_aspect_ratio_value( $dimensions_block_styles['aspectRatio'] ) | |
| 109 | 125 | ) { |
| 110 | 126 | $dimensions_block_styles['minHeight'] = 'unset'; |
| 111 | 127 | $dimensions_block_styles['height'] = 'unset'; |
| 112 | 128 | } elseif ( |
| @@ -141,9 +157,9 @@ | ||
| 141 | 157 | if ( ! empty( $styles['classnames'] ) ) { |
| 142 | 158 | foreach ( explode( ' ', $styles['classnames'] ) as $class_name ) { |
| 143 | 159 | if ( |
| 144 | 160 | str_contains( $class_name, 'aspect-ratio' ) && |
| 145 | - ! isset( $block_attributes['style']['dimensions']['aspectRatio'] ) | |
| 161 | + ! gutenberg_is_explicit_aspect_ratio_value( $block_attributes['style']['dimensions']['aspectRatio'] ?? null ) | |
| 146 | 162 | ) { |
| 147 | 163 | continue; |
| 148 | 164 | } |
| 149 | 165 | $tags->add_class( $class_name ); |