PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | lib/block-supports/dimensions.php +21 -5 23.2.2 → 24.1.0 View file →
@@ -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 );