You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detect wp:button blocks where "width":N is set in JSON but the outer
<div> is missing has-custom-width / wp-block-button__width-{N} classes,
or the inner <a> still carries width:{N}% inline style.
WordPress core/button save() expresses percentage width via CSS classes
on the outer div — not inline style — so any mismatch causes a block
validation failure in the editor. Caught by this rule before deployment.
Also bump bin/pt-cli application version from 2.0.0 to 2.2.3.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
7
+
## [2.2.3] - 2026-05-13
8
+
9
+
### Added
10
+
11
+
-**`button-width-classes` rule** (`BaseRules`) — detects `wp:button` blocks that have `"width":N` in their JSON but whose HTML outer `<div>` is missing the `has-custom-width` and/or `wp-block-button__width-{N}` classes, or where the inner `<a>` still carries a `width:{N}%` inline style. WordPress's `core/button` save function expresses percentage width via CSS classes on the outer div — not inline style — so any mismatch causes a block validation failure in the editor.
if (!str_contains($html, 'has-custom-width') || !str_contains($html, "wp-block-button__width-{$pct}")) {
271
+
return [$this->violation(
272
+
'button-width-classes',
273
+
"wp:button has \"width\":{$pct} but the outer <div> is missing has-custom-width and/or wp-block-button__width-{$pct} — add both classes and remove width:{$pct}% from the <a> inline style to match core/button save() output"
274
+
)];
275
+
}
276
+
if (str_contains($html, "width:{$pct}%")) {
277
+
return [$this->violation(
278
+
'button-width-classes',
279
+
"wp:button has \"width\":{$pct} but the <a> still has width:{$pct}% inline style — remove it (save() expresses width via has-custom-width + wp-block-button__width-{$pct} classes on the outer div, not inline style)"
0 commit comments