Skip to content

Block Supports: Add the translate feature to the transform block support - #15465

Draft
aaronrobertshaw wants to merge 9 commits into
WordPress:trunkfrom
aaronrobertshaw:backport/86282-transform-translate
Draft

aaronrobertshaw wants to merge 9 commits into
WordPress:trunkfrom
aaronrobertshaw:backport/86282-transform-translate

Conversation

@aaronrobertshaw

@aaronrobertshaw aaronrobertshaw commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

This builds on #15408 and should land after it. Only the last commit is new for review. The earlier commits belong to #15408.

Backport of Gutenberg PR WordPress/gutenberg#86282

Trac ticket: https://core.trac.wordpress.org/ticket/66467

Adds X and Y offsets to the transform block support. Each axis set outputs its own custom property, --wp--style--translate-x or --wp--style--translate-y, plus translate: var(--wp--style--translate-x, 0) var(--wp--style--translate-y, 0). An offset combines with a rotation and with existing block transforms. Each style layer sets only its own axes.

This PR backports:

  • the translate feature in the transform block support, as an inline style. An axis left out comes from global styles or other styles. It is 0 when none sets it,
  • keeping each valid axis in WP_Theme_JSON::remove_insecure_properties(),
  • transform.translate in WP_Theme_JSON settings and styles, keeping only the x and y axes, switched on by appearanceTools,
  • the transform.translate style engine definition, with one length or percentage per axis,
  • translate in safecss_filter_attr(), limited to one or two lengths or percentages or CSS functions such as var(). The two axis custom properties are limited to one length or percentage,
  • and the accompanying tests.

The block opt-ins, the setting in Core's theme.json, the editor UI and the @property rules that stop nested blocks inheriting an offset arrive later with the Gutenberg package update.

Testing instructions

  1. In the active theme's theme.json, add "transform": { "translate": { "x": "10px", "y": "-50%" } } under styles.blocks.core/group.
  2. View a page that contains a Group block.
  3. Check the global-styles-inline-css style tag contains :root :where(.wp-block-group){--wp--style--translate-x: 10px;--wp--style--translate-y: -50%;translate: var(--wp--style--translate-x, 0) var(--wp--style--translate-y, 0);}.
  4. Change the Group x value to calc(1px + 2px) and confirm the rule disappears.

Without this PR there is no translate rule at all.

Use of AI

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: The mechanical port, tests and this description; I reviewed and edited the PR.

@aaronrobertshaw aaronrobertshaw self-assigned this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@aaronrobertshaw
aaronrobertshaw force-pushed the backport/86282-transform-translate branch 3 times, most recently from 2826238 to d6f1bcb Compare November 5, 2026 10:08
Backports the PHP side of Gutenberg PR 86240: the transform block support, the transform.rotate setting and style in WP_Theme_JSON (blocks and block style variations only), the style engine rotate definition, and rotate in KSES limited to a single angle.
Adds the D modifier to WP_Style_Engine::VALID_ANGLE_PATTERN. Without it, $ matches before a final newline, so "45deg\n" passed validation.
@aaronrobertshaw
aaronrobertshaw force-pushed the backport/86282-transform-translate branch from 98c9a3e to 8cd0ea2 Compare November 11, 2026 03:45
Transforms are for blocks only. Element styles in a block's style
attribute, including viewport states, passed their whole style object
to the style engine, so a saved or pasted element transform still
output CSS. Drop the transform key from element styles before they
reach the style engine.

See #66468.
Transforms now follow border and shadow. The rotation is returned as an
inline style by an apply callback, and a block that applies it to an
inner element skips serialization and calls
wp_get_transform_classes_and_styles(). Feature selectors are left to
global styles and block style states.

Transform tools are switched on by appearanceTools, and theme.json
validates transform values with one style engine call.
…ort.

An offset is saved inline like the rotation. It replaces the global
styles offset whole, and an axis it leaves out is 0, as in CSS.

Transform tools, including translate, are switched on by appearanceTools.
@aaronrobertshaw
aaronrobertshaw force-pushed the backport/86282-transform-translate branch from c091906 to d4b30ab Compare November 17, 2026 11:26
Each style layer now sets only the axes it has, as --wp--style--translate-x and --wp--style--translate-y, and translate reads both with var(). kses keeps the axis properties and translate with CSS functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant