Make WordPress Core

Changeset 55175


Ignore:
Timestamp:
02/01/2023 04:13:49 PM (2 years ago)
Author:
hellofromTonya
Message:

Editor: Introduce minimum height dimensions block support.

This changeset adds the new dimension feature's PHP code for supporting minimum height in the block editor inspector and in global styles. Minimum height is quite useful for defining the minimum vertical dimensions of a block, while allowing it to expand beyond that size.

In this changeset:

  • Adds support in theme.json.
  • Adds support in the style engine.
  • Adds support in wp_apply_dimensions_support().
  • Renames the setting from '__experimentalDimensions' to dimensions in wp_register_dimensions_support().
  • Adds PHPUnit tests.

Is renaming '__experimentalDimensions' a backwards-compatibility (BC) break?

Though the setting has been in the code since 5.9.0, it was never wired to anything, ie it did not expose any controls or styles. Notice in wp_register_dimensions_support() and wp_apply_dimensions_support() prior to this changeset, there are inline comments as placeholders for height and width support, but no code.

If a developer opted in to use it, it had no effect.

A search in wp.org's plugin and themes repo showed no instances of this experimental setting.

Given there was no functionality attached to it (until this changeset), no change in behavior or effect from removing it, and no usage found in the plugins and themes repository, it does appear to be a BC break.

References:

Follow-up to [53076], [52069].

Props andrewserong, aaronrobertshaw , costdev, hellofromTonya, isabel_brison, joen, paaljoachim, mukesh27, ntsekouras, oandregal, ramonopoly.
Fixes #57582.

Location:
trunk
Files:
1 added
5 edited

Legend:

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

    r53076 r55175  
    3030    }
    3131
    32     $has_dimensions_support = block_has_support( $block_type, array( '__experimentalDimensions' ), false );
    33     // Future block supports such as height & width will be added here.
     32    $has_dimensions_support = block_has_support( $block_type, array( 'dimensions' ), false );
    3433
    3534    if ( $has_dimensions_support ) {
     
    4544 *
    4645 * @since 5.9.0
     46 * @since 6.2.0 Added `minHeight` support.
    4747 * @access private
    4848 *
     
    5252 */
    5353function wp_apply_dimensions_support( $block_type, $block_attributes ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
    54     if ( wp_should_skip_block_supports_serialization( $block_type, '__experimentalDimensions' ) ) {
     54    if ( wp_should_skip_block_supports_serialization( $block_type, 'dimensions' ) ) {
    5555        return array();
    5656    }
    5757
    58     $styles = array();
     58    $attributes = array();
    5959
    60     // Height support to be added in near future.
    6160    // Width support to be added in near future.
    6261
    63     return empty( $styles ) ? array() : array( 'style' => implode( ' ', $styles ) );
     62    $has_min_height_support = block_has_support( $block_type, array( 'dimensions', 'minHeight' ), false );
     63    $block_styles           = isset( $block_attributes['style'] ) ? $block_attributes['style'] : null;
     64
     65    if ( ! $block_styles ) {
     66        return $attributes;
     67    }
     68
     69    $skip_min_height                      = wp_should_skip_block_supports_serialization( $block_type, 'dimensions', 'minHeight' );
     70    $dimensions_block_styles              = array();
     71    $dimensions_block_styles['minHeight'] = $has_min_height_support && ! $skip_min_height ? _wp_array_get( $block_styles, array( 'dimensions', 'minHeight' ), null ) : null;
     72    $styles                               = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
     73
     74    if ( ! empty( $styles['css'] ) ) {
     75        $attributes['style'] = $styles['css'];
     76    }
     77
     78    return $attributes;
    6479}
    6580
  • trunk/src/wp-includes/class-wp-theme-json.php

    r55172 r55175  
    193193     *              `--wp--style--root--padding-*`, and `box-shadow` properties,
    194194     *              removed the `--wp--style--block-gap` property.
    195      * @since 6.2.0 Added `outline-*` properties.
     195     * @since 6.2.0 Added `outline-*`, and `min-height` properties.
    196196     *
    197197     * @var array
     
    232232        'margin-bottom'                     => array( 'spacing', 'margin', 'bottom' ),
    233233        'margin-left'                       => array( 'spacing', 'margin', 'left' ),
     234        'min-height'                        => array( 'dimensions', 'minHeight' ),
    234235        'outline-color'                     => array( 'outline', 'color' ),
    235236        'outline-offset'                    => array( 'outline', 'offset' ),
     
    294295     * @since 6.0.0 Added `color.defaultDuotone`.
    295296     * @since 6.1.0 Added `layout.definitions` and `useRootPaddingAwareAlignments`.
     297     * @since 6.2.0 Added `dimensions.minHeight`.
    296298     * @var array
    297299     */
     
    320322        ),
    321323        'custom'                        => null,
     324        'dimensions'                    => array(
     325            'minHeight' => null,
     326        ),
    322327        'layout'                        => array(
    323328            'contentSize' => null,
     
    359364     *              added new property `shadow`,
    360365     *              updated `blockGap` to be allowed at any level.
    361      * @since 6.2.0 Added `outline` properties.
     366     * @since 6.2.0 Added `outline`, and `minHeight` properties.
    362367     *
    363368     * @var array
     
    378383            'gradient'   => null,
    379384            'text'       => null,
     385        ),
     386        'dimensions' => array(
     387            'minHeight' => null,
    380388        ),
    381389        'filter'     => array(
     
    491499     *
    492500     * @since 6.0.0
     501     * @since 6.2.0 Added `dimensions.minHeight`.
    493502     * @var array
    494503     */
     
    499508        array( 'border', 'width' ),
    500509        array( 'color', 'link' ),
     510        array( 'dimensions', 'minHeight' ),
    501511        array( 'spacing', 'blockGap' ),
    502512        array( 'spacing', 'margin' ),
  • trunk/src/wp-includes/style-engine/class-wp-style-engine.php

    r54481 r55175  
    138138            ),
    139139        ),
     140        'dimensions' => array(
     141            'minHeight' => array(
     142                'property_keys' => array(
     143                    'default' => 'min-height',
     144                ),
     145                'path'          => array( 'dimensions', 'minHeight' ),
     146                'css_vars'      => array(
     147                    'spacing' => '--wp--preset--spacing--$slug',
     148                ),
     149            ),
     150        ),
    140151        'spacing'    => array(
    141152            'padding' => array(
  • trunk/tests/phpunit/tests/style-engine/styleEngine.php

    r54156 r55175  
    167167            ),
    168168
     169            'inline_valid_dimensions_style'                => array(
     170                'block_styles'    => array(
     171                    'dimensions' => array(
     172                        'minHeight' => '50vh',
     173                    ),
     174                ),
     175                'options'         => null,
     176                'expected_output' => array(
     177                    'css'          => 'min-height:50vh;',
     178                    'declarations' => array(
     179                        'min-height' => '50vh',
     180                    ),
     181                ),
     182            ),
     183
    169184            'inline_valid_typography_style'                => array(
    170185                'block_styles'    => array(
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r55172 r55175  
    242242                'link' => true,
    243243            ),
     244            'dimensions' => array(
     245                'minHeight' => true,
     246            ),
    244247            'spacing'    => array(
    245248                'blockGap' => false,
     
    265268                    'color'      => array(
    266269                        'link' => true,
     270                    ),
     271                    'dimensions' => array(
     272                        'minHeight' => true,
    267273                    ),
    268274                    'spacing'    => array(
Note: See TracChangeset for help on using the changeset viewer.