Skip to content

Commit 3fe3acf

Browse files
committed
Block Supports: Add height to dimensions supports
This PR introduces `dimensions.height` to the list of available block supports. This block support enables, in the future, the removal of the custom height controls in blocks such as Image, Spacer and others in favor of customizations via block supports. Props aaronrobertshaw, andrewserong, ramonopoly, welcher, wildworks, youknowriad. Fixes #64202. git-svn-id: https://develop.svn.wordpress.org/trunk@61620 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5ca0471 commit 3fe3acf

5 files changed

Lines changed: 88 additions & 5 deletions

File tree

src/wp-includes/block-supports/dimensions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function wp_apply_dimensions_support( $block_type, $block_attributes ) {
6464
}
6565

6666
$dimensions_block_styles = array();
67-
$supported_features = array( 'minHeight', 'width' );
67+
$supported_features = array( 'minHeight', 'height', 'width' );
6868

6969
foreach ( $supported_features as $feature ) {
7070
$has_support = block_has_support( $block_type, array( 'dimensions', $feature ), false );

src/wp-includes/class-wp-theme-json.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class WP_Theme_JSON {
237237
* @since 6.5.0 Added `aspect-ratio` property.
238238
* @since 6.6.0 Added `background-[image|position|repeat|size]` properties.
239239
* @since 6.7.0 Added `background-attachment` property.
240-
* @since 7.0.0 Added `dimensions.width`.
240+
* @since 7.0.0 Added `dimensions.width` and `dimensions.height`.
241241
* @var array
242242
*/
243243
const PROPERTIES_METADATA = array(
@@ -302,6 +302,7 @@ class WP_Theme_JSON {
302302
'text-transform' => array( 'typography', 'textTransform' ),
303303
'filter' => array( 'filter', 'duotone' ),
304304
'box-shadow' => array( 'shadow' ),
305+
'height' => array( 'dimensions', 'height' ),
305306
'width' => array( 'dimensions', 'width' ),
306307
'writing-mode' => array( 'typography', 'writingMode' ),
307308
);
@@ -398,7 +399,7 @@ class WP_Theme_JSON {
398399
* 'typography.defaultFontSizes', and 'spacing.defaultSpacingSizes'.
399400
* @since 6.9.0 Added support for `border.radiusSizes`.
400401
* @since 7.0.0 Added type markers to the schema for boolean values.
401-
* Added support for `dimensions.width`.
402+
* Added support for `dimensions.width` and `dimensions.height`.
402403
* @var array
403404
*/
404405
const VALID_SETTINGS = array(
@@ -437,6 +438,7 @@ class WP_Theme_JSON {
437438
'aspectRatio' => null,
438439
'aspectRatios' => null,
439440
'defaultAspectRatios' => null,
441+
'height' => null,
440442
'minHeight' => null,
441443
'width' => null,
442444
),
@@ -532,7 +534,7 @@ class WP_Theme_JSON {
532534
* @since 6.3.0 Added support for `typography.textColumns`.
533535
* @since 6.5.0 Added support for `dimensions.aspectRatio`.
534536
* @since 6.6.0 Added `background` sub properties to top-level only.
535-
* @since 7.0.0 Added support for `dimensions.width`.
537+
* @since 7.0.0 Added support for `dimensions.width` and `dimensions.height`.
536538
* @var array
537539
*/
538540
const VALID_STYLES = array(
@@ -560,6 +562,7 @@ class WP_Theme_JSON {
560562
),
561563
'dimensions' => array(
562564
'aspectRatio' => null,
565+
'height' => null,
563566
'minHeight' => null,
564567
'width' => null,
565568
),
@@ -772,7 +775,7 @@ public static function get_element_class_name( $element ) {
772775
* @since 6.2.0 Added `dimensions.minHeight` and `position.sticky`.
773776
* @since 6.4.0 Added `background.backgroundImage`.
774777
* @since 6.5.0 Added `background.backgroundSize` and `dimensions.aspectRatio`.
775-
* @since 7.0.0 Added `dimensions.width`.
778+
* @since 7.0.0 Added `dimensions.width` and `dimensions.height`.
776779
* @var array
777780
*/
778781
const APPEARANCE_TOOLS_OPT_INS = array(
@@ -787,6 +790,7 @@ public static function get_element_class_name( $element ) {
787790
array( 'color', 'button' ),
788791
array( 'color', 'caption' ),
789792
array( 'dimensions', 'aspectRatio' ),
793+
array( 'dimensions', 'height' ),
790794
array( 'dimensions', 'minHeight' ),
791795
array( 'dimensions', 'width' ),
792796
array( 'position', 'sticky' ),

src/wp-includes/style-engine/class-wp-style-engine.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ final class WP_Style_Engine {
210210
'has-aspect-ratio' => true,
211211
),
212212
),
213+
'height' => array(
214+
'property_keys' => array(
215+
'default' => 'height',
216+
),
217+
'path' => array( 'dimensions', 'height' ),
218+
),
213219
'minHeight' => array(
214220
'property_keys' => array(
215221
'default' => 'min-height',

tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,75 @@ public function data_width_block_support() {
171171
),
172172
);
173173
}
174+
175+
/**
176+
* Tests that height block support works as expected.
177+
*
178+
* @ticket 64202
179+
*
180+
* @covers ::wp_apply_dimensions_support
181+
*
182+
* @dataProvider data_height_block_support
183+
*
184+
* @param string $block_name The test block name to register.
185+
* @param mixed $dimensions The dimensions block support settings.
186+
* @param mixed $expected The expected results.
187+
*/
188+
public function test_height_block_support( $block_name, $dimensions, $expected ) {
189+
$this->test_block_name = $block_name;
190+
register_block_type(
191+
$this->test_block_name,
192+
array(
193+
'api_version' => 2,
194+
'attributes' => array(
195+
'style' => array(
196+
'type' => 'object',
197+
),
198+
),
199+
'supports' => array(
200+
'dimensions' => $dimensions,
201+
),
202+
)
203+
);
204+
$registry = WP_Block_Type_Registry::get_instance();
205+
$block_type = $registry->get_registered( $this->test_block_name );
206+
$block_attrs = array(
207+
'style' => array(
208+
'dimensions' => array(
209+
'height' => '400px',
210+
),
211+
),
212+
);
213+
214+
$actual = wp_apply_dimensions_support( $block_type, $block_attrs );
215+
216+
$this->assertSame( $expected, $actual );
217+
}
218+
219+
/**
220+
* Data provider.
221+
*
222+
* @return array
223+
*/
224+
public function data_height_block_support() {
225+
return array(
226+
'style is applied' => array(
227+
'block_name' => 'test/height-style-is-applied',
228+
'dimensions' => array(
229+
'height' => true,
230+
),
231+
'expected' => array(
232+
'style' => 'height:400px;',
233+
),
234+
),
235+
'style output is skipped when individual feature serialization is skipped' => array(
236+
'block_name' => 'test/height-with-individual-skipped-serialization-block-supports',
237+
'dimensions' => array(
238+
'height' => true,
239+
'__experimentalSkipSerialization' => array( 'height' ),
240+
),
241+
'expected' => array(),
242+
),
243+
);
244+
}
174245
}

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ public function test_get_settings_appearance_true_opts_in() {
280280
),
281281
'dimensions' => array(
282282
'aspectRatio' => true,
283+
'height' => true,
283284
'minHeight' => true,
284285
'width' => true,
285286
),
@@ -320,6 +321,7 @@ public function test_get_settings_appearance_true_opts_in() {
320321
),
321322
'dimensions' => array(
322323
'aspectRatio' => true,
324+
'height' => true,
323325
'minHeight' => true,
324326
'width' => true,
325327
),

0 commit comments

Comments
 (0)