Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ New styles options are integrated into theme.json on a regular basis. Knowing th
| `spacing.margin.left` | 5.8 | 5.9 |
| `spacing.margin.bottom` | 5.8 | 5.9 |
| `spacing.blockGap` | 5.9 | 5.9 |
| `spacing.blockBackgroundPadding` | 7.2 | N/A |
| `background.backgroundAttachment` | 6.7 | 6.7 |
| `background.backgroundImage` | 6.4 | 6.5 |
| `background.backgroundPosition` | 6.6 | 6.6 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ Spacing styles.

| Property | Description | Type |
| -------- | ----------- | ---- |
| blockBackgroundPadding | Sets the `--wp--style--block-background-padding` CSS custom property, used as the default padding by blocks that add padding when they have a background color. | `string`, `{ ref }` |
| blockGap | Sets the `--wp--style--block-gap` CSS custom property when settings.spacing.blockGap is true. | `string`, `{ ref }` |
| margin | Margin styles. | `{ top, right, bottom, left }` |
| padding | Padding styles. | `{ top, right, bottom, left }` |
Expand Down
144 changes: 74 additions & 70 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,77 +243,79 @@ class WP_Theme_JSON_Gutenberg {
* @since 6.6.0 Added `background-[image|position|repeat|size]` properties.
* @since 7.0.0 Added `dimensions.width`, `dimensions.height`, and
* `typography.textIndent` properties.
* @since 7.2.0 Added the `--wp--style--block-background-padding` property.
*
* @var array
*/
const PROPERTIES_METADATA = array(
'aspect-ratio' => array( 'dimensions', 'aspectRatio' ),
'background' => array( 'color', 'gradient' ),
'background-color' => array( 'color', 'background' ),
'background-image' => array( 'background', 'backgroundImage' ),
'background-position' => array( 'background', 'backgroundPosition' ),
'background-repeat' => array( 'background', 'backgroundRepeat' ),
'background-size' => array( 'background', 'backgroundSize' ),
'background-attachment' => array( 'background', 'backgroundAttachment' ),
'border-radius' => array( 'border', 'radius' ),
'border-top-left-radius' => array( 'border', 'radius', 'topLeft' ),
'border-top-right-radius' => array( 'border', 'radius', 'topRight' ),
'border-bottom-left-radius' => array( 'border', 'radius', 'bottomLeft' ),
'border-bottom-right-radius' => array( 'border', 'radius', 'bottomRight' ),
'border-color' => array( 'border', 'color' ),
'border-width' => array( 'border', 'width' ),
'border-style' => array( 'border', 'style' ),
'border-top-color' => array( 'border', 'top', 'color' ),
'border-top-width' => array( 'border', 'top', 'width' ),
'border-top-style' => array( 'border', 'top', 'style' ),
'border-right-color' => array( 'border', 'right', 'color' ),
'border-right-width' => array( 'border', 'right', 'width' ),
'border-right-style' => array( 'border', 'right', 'style' ),
'border-bottom-color' => array( 'border', 'bottom', 'color' ),
'border-bottom-width' => array( 'border', 'bottom', 'width' ),
'border-bottom-style' => array( 'border', 'bottom', 'style' ),
'border-left-color' => array( 'border', 'left', 'color' ),
'border-left-width' => array( 'border', 'left', 'width' ),
'border-left-style' => array( 'border', 'left', 'style' ),
'color' => array( 'color', 'text' ),
'text-align' => array( 'typography', 'textAlign' ),
'column-count' => array( 'typography', 'textColumns' ),
'font-family' => array( 'typography', 'fontFamily' ),
'font-size' => array( 'typography', 'fontSize' ),
'font-style' => array( 'typography', 'fontStyle' ),
'font-weight' => array( 'typography', 'fontWeight' ),
'letter-spacing' => array( 'typography', 'letterSpacing' ),
'line-height' => array( 'typography', 'lineHeight' ),
'margin' => array( 'spacing', 'margin' ),
'margin-top' => array( 'spacing', 'margin', 'top' ),
'margin-right' => array( 'spacing', 'margin', 'right' ),
'margin-bottom' => array( 'spacing', 'margin', 'bottom' ),
'margin-left' => array( 'spacing', 'margin', 'left' ),
'min-height' => array( 'dimensions', 'minHeight' ),
'min-width' => array( 'dimensions', 'minWidth' ),
'outline-color' => array( 'outline', 'color' ),
'outline-offset' => array( 'outline', 'offset' ),
'outline-style' => array( 'outline', 'style' ),
'outline-width' => array( 'outline', 'width' ),
'padding' => array( 'spacing', 'padding' ),
'padding-top' => array( 'spacing', 'padding', 'top' ),
'padding-right' => array( 'spacing', 'padding', 'right' ),
'padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
'padding-left' => array( 'spacing', 'padding', 'left' ),
'--wp--style--root--padding' => array( 'spacing', 'padding' ),
'--wp--style--root--padding-top' => array( 'spacing', 'padding', 'top' ),
'--wp--style--root--padding-right' => array( 'spacing', 'padding', 'right' ),
'--wp--style--root--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
'--wp--style--root--padding-left' => array( 'spacing', 'padding', 'left' ),
'text-decoration' => array( 'typography', 'textDecoration' ),
'text-shadow' => array( 'typography', 'textShadow' ),
'text-transform' => array( 'typography', 'textTransform' ),
'text-indent' => array( 'typography', 'textIndent' ),
'filter' => array( 'filter', 'duotone' ),
'box-shadow' => array( 'shadow' ),
'height' => array( 'dimensions', 'height' ),
'width' => array( 'dimensions', 'width' ),
'writing-mode' => array( 'typography', 'writingMode' ),
'aspect-ratio' => array( 'dimensions', 'aspectRatio' ),
'background' => array( 'color', 'gradient' ),
'background-color' => array( 'color', 'background' ),
'background-image' => array( 'background', 'backgroundImage' ),
'background-position' => array( 'background', 'backgroundPosition' ),
'background-repeat' => array( 'background', 'backgroundRepeat' ),
'background-size' => array( 'background', 'backgroundSize' ),
'background-attachment' => array( 'background', 'backgroundAttachment' ),
'border-radius' => array( 'border', 'radius' ),
'border-top-left-radius' => array( 'border', 'radius', 'topLeft' ),
'border-top-right-radius' => array( 'border', 'radius', 'topRight' ),
'border-bottom-left-radius' => array( 'border', 'radius', 'bottomLeft' ),
'border-bottom-right-radius' => array( 'border', 'radius', 'bottomRight' ),
'border-color' => array( 'border', 'color' ),
'border-width' => array( 'border', 'width' ),
'border-style' => array( 'border', 'style' ),
'border-top-color' => array( 'border', 'top', 'color' ),
'border-top-width' => array( 'border', 'top', 'width' ),
'border-top-style' => array( 'border', 'top', 'style' ),
'border-right-color' => array( 'border', 'right', 'color' ),
'border-right-width' => array( 'border', 'right', 'width' ),
'border-right-style' => array( 'border', 'right', 'style' ),
'border-bottom-color' => array( 'border', 'bottom', 'color' ),
'border-bottom-width' => array( 'border', 'bottom', 'width' ),
'border-bottom-style' => array( 'border', 'bottom', 'style' ),
'border-left-color' => array( 'border', 'left', 'color' ),
'border-left-width' => array( 'border', 'left', 'width' ),
'border-left-style' => array( 'border', 'left', 'style' ),
'color' => array( 'color', 'text' ),
'text-align' => array( 'typography', 'textAlign' ),
'column-count' => array( 'typography', 'textColumns' ),
'font-family' => array( 'typography', 'fontFamily' ),
'font-size' => array( 'typography', 'fontSize' ),
'font-style' => array( 'typography', 'fontStyle' ),
'font-weight' => array( 'typography', 'fontWeight' ),
'letter-spacing' => array( 'typography', 'letterSpacing' ),
'line-height' => array( 'typography', 'lineHeight' ),
'margin' => array( 'spacing', 'margin' ),
'margin-top' => array( 'spacing', 'margin', 'top' ),
'margin-right' => array( 'spacing', 'margin', 'right' ),
'margin-bottom' => array( 'spacing', 'margin', 'bottom' ),
'margin-left' => array( 'spacing', 'margin', 'left' ),
'min-height' => array( 'dimensions', 'minHeight' ),
'min-width' => array( 'dimensions', 'minWidth' ),
'outline-color' => array( 'outline', 'color' ),
'outline-offset' => array( 'outline', 'offset' ),
'outline-style' => array( 'outline', 'style' ),
'outline-width' => array( 'outline', 'width' ),
'padding' => array( 'spacing', 'padding' ),
'padding-top' => array( 'spacing', 'padding', 'top' ),
'padding-right' => array( 'spacing', 'padding', 'right' ),
'padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
'padding-left' => array( 'spacing', 'padding', 'left' ),
'--wp--style--root--padding' => array( 'spacing', 'padding' ),
'--wp--style--root--padding-top' => array( 'spacing', 'padding', 'top' ),
'--wp--style--root--padding-right' => array( 'spacing', 'padding', 'right' ),
'--wp--style--root--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
'--wp--style--root--padding-left' => array( 'spacing', 'padding', 'left' ),
'--wp--style--block-background-padding' => array( 'spacing', 'blockBackgroundPadding' ),
'text-decoration' => array( 'typography', 'textDecoration' ),
'text-shadow' => array( 'typography', 'textShadow' ),
'text-transform' => array( 'typography', 'textTransform' ),
'text-indent' => array( 'typography', 'textIndent' ),
'filter' => array( 'filter', 'duotone' ),
'box-shadow' => array( 'shadow' ),
'height' => array( 'dimensions', 'height' ),
'width' => array( 'dimensions', 'width' ),
'writing-mode' => array( 'typography', 'writingMode' ),
);

/**
Expand Down Expand Up @@ -533,6 +535,7 @@ class WP_Theme_JSON_Gutenberg {
* @since 6.6.0 Added `dimensions.aspectRatio`.
* @since 7.0.0 Added `dimensions.width`, `dimensions.height`, and
* `typography.textIndent` properties.
* @since 7.2.0 Added `spacing.blockBackgroundPadding`.
* @var array
*/
const VALID_STYLES = array(
Expand Down Expand Up @@ -577,9 +580,10 @@ class WP_Theme_JSON_Gutenberg {
),
'shadow' => null,
'spacing' => array(
'margin' => null,
'padding' => null,
'blockGap' => null,
'margin' => null,
'padding' => null,
'blockGap' => null,
'blockBackgroundPadding' => null,
),
'typography' => array(
'fontFamily' => null,
Expand Down
4 changes: 4 additions & 0 deletions packages/blocks/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Block variations and `block` type block transforms accept a `shortcut` property, declaring a keyboard shortcut that applies the variation or transform to the selected block. See the [block variations](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/) and [block transforms](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-transforms/) documentation ([#81588](https://github.com/WordPress/gutenberg/pull/81588)).

### Enhancements

- Add `spacing.blockBackgroundPadding` to the style properties, so a `theme.json` value is emitted as the `--wp--style--block-background-padding` custom property ([#82057](https://github.com/WordPress/gutenberg/pull/82057)).

## 15.26.0 (2026-08-12)

### Internal
Expand Down
3 changes: 3 additions & 0 deletions packages/blocks/src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = {
},
rootOnly: true,
},
'--wp--style--block-background-padding': {
value: [ 'spacing', 'blockBackgroundPadding' ],
},
};

export const __EXPERIMENTAL_ELEMENTS: Record< string, string > = {
Expand Down
4 changes: 4 additions & 0 deletions packages/global-styles-engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Add `spacing.blockBackgroundPadding` to the styles types ([#82057](https://github.com/WordPress/gutenberg/pull/82057)).

### Bug Fixes

- Use the row block spacing value for Flow and Constrained layouts when Global Styles defines separate row and column values ([#81476](https://github.com/WordPress/gutenberg/pull/81476)).
Expand Down
42 changes: 42 additions & 0 deletions packages/global-styles-engine/src/test/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jest.mock( '@wordpress/blocks', () => ( {
value: [ 'filter', 'duotone' ],
support: [ 'filter', 'duotone' ],
},
'--wp--style--block-background-padding': {
value: [ 'spacing', 'blockBackgroundPadding' ],
},
},
__EXPERIMENTAL_ELEMENTS: {
link: 'a:where(:not(.wp-element-button))',
Expand Down Expand Up @@ -446,6 +449,45 @@ describe( 'global styles renderer', () => {
);
} );

it( 'outputs the block background padding custom property for root and block values', () => {
const tree: GlobalStylesConfig = {
styles: {
spacing: {
blockBackgroundPadding: '0',
},
blocks: {
'core/group': {
spacing: {
blockBackgroundPadding: '1em 2em',
},
},
},
},
};
const blockSelectors = {
'core/group': {
selector: '.wp-block-group',
},
};

const result = transformToStyles(
Object.freeze( tree ),
blockSelectors,
true,
false,
false,
true,
minimalStyleOptions
);

expect( result ).toContain(
'body{--wp--style--block-background-padding: 0;}'
);
expect( result ).toContain(
':root :where(.wp-block-group){--wp--style--block-background-padding: 1em 2em;}'
);
} );

it( 'should return a ruleset', () => {
const tree = {
settings: {
Expand Down
1 change: 1 addition & 0 deletions packages/global-styles-engine/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export interface GlobalStylesStyles {
padding?: UnresolvedValue | Record< string, UnresolvedValue >;
margin?: UnresolvedValue | Record< string, UnresolvedValue >;
blockGap?: string | { top: string; left: string };
blockBackgroundPadding?: UnresolvedValue;
};
background?: BackgroundStyle;
border?: {
Expand Down
23 changes: 23 additions & 0 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,29 @@ public function test_get_stylesheet_renders_enabled_protected_properties() {
$this->assertSameCSS( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
}

public function test_get_stylesheet_outputs_block_background_padding_custom_property() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'styles' => array(
'spacing' => array(
'blockBackgroundPadding' => '0',
),
'blocks' => array(
'core/group' => array(
'spacing' => array(
'blockBackgroundPadding' => '1em 2em',
),
),
),
),
)
);

$expected = static::$base_styles . 'body{--wp--style--block-background-padding: 0;}:root :where(.wp-block-group){--wp--style--block-background-padding: 1em 2em;}';
$this->assertSameCSS( $expected, $theme_json->get_stylesheet( array( 'styles' ) ) );
}

public function test_get_stylesheet_preset_classes_work_with_compounded_selectors() {
$theme_json = new WP_Theme_JSON_Gutenberg(
array(
Expand Down
7 changes: 7 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,13 @@
"description": "Spacing styles.",
"type": "object",
"properties": {
"blockBackgroundPadding": {
"description": "Sets the `--wp--style--block-background-padding` CSS custom property, used as the default padding by blocks that add padding when they have a background color.",
"oneOf": [
{ "type": "string" },
{ "$ref": "#/definitions/refComplete" }
]
},
"blockGap": {
"description": "Sets the `--wp--style--block-gap` CSS custom property when settings.spacing.blockGap is true.",
"oneOf": [
Expand Down
Loading