Make WordPress Core

Changeset 61620


Ignore:
Timestamp:
02/12/2026 05:43:12 AM (7 weeks ago)
Author:
ramonopoly
Message:

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.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/dimensions.php

    r61619 r61620  
    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 ) {
  • trunk/src/wp-includes/class-wp-theme-json.php

    r61619 r61620  
    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     */
     
    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' ),
     
    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     */
     
    438439            'aspectRatios'        => null,
    439440            'defaultAspectRatios' => null,
     441            'height'              => null,
    440442            'minHeight'           => null,
    441443            'width'               => null,
     
    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     */
     
    561563        'dimensions' => array(
    562564            'aspectRatio' => null,
     565            'height'      => null,
    563566            'minHeight'   => null,
    564567            'width'       => null,
     
    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     */
     
    788791        array( 'color', 'caption' ),
    789792        array( 'dimensions', 'aspectRatio' ),
     793        array( 'dimensions', 'height' ),
    790794        array( 'dimensions', 'minHeight' ),
    791795        array( 'dimensions', 'width' ),
  • trunk/src/wp-includes/style-engine/class-wp-style-engine.php

    r61619 r61620  
    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(
  • trunk/tests/phpunit/tests/block-supports/wpApplyDimensionsSupport.php

    r61619 r61620  
    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}
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r61619 r61620  
    281281            'dimensions' => array(
    282282                'aspectRatio' => true,
     283                'height'      => true,
    283284                'minHeight'   => true,
    284285                'width'       => true,
     
    321322                    'dimensions' => array(
    322323                        'aspectRatio' => true,
     324                        'height'      => true,
    323325                        'minHeight'   => true,
    324326                        'width'       => true,
Note: See TracChangeset for help on using the changeset viewer.