Fix/button Width Classes Rule#7
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This release adds the
button-width-classescompliance rule toBaseRules, addressing a class of block validation failures that occur when pattern files express button percentage widths via inline styles rather than the CSS classes emitted by WordPress'score/buttonsave()function. The rule detectswp:buttonblocks that carry a"width":Nattribute in their block comment JSON but whose corresponding HTML outer<div>is missing one or both of the requiredhas-custom-widthandwp-block-button__width-{N}classes, or where the inner<a>element retains awidth:{N}%inline style. Because WordPress's block save function writes width as classes on the outer wrapper — never as inline style — any mismatch causes the editor to report a block validation failure and prompt the user to attempt recovery. The version string inbin/pt-clihas been bumped to2.2.3to reflect this addition.Rule Implementation:
BaseRules::checkButtonWidthClasses()parses content line-by-line, identifies<!-- wp:buttoncomments containing a"width":Nattribute, and scans the immediately following HTML lines (up to two) for the correspondingwp-block-buttonwrapper div.<div>is missinghas-custom-widthand/orwp-block-button__width-{N}, and a separate one when the<a>element retains awidth:{N}%inline style, providing precise remediation guidance in each case.check()pipeline betweencheckButtonClassNameOrderandcheckCoverBlockMinHeight, maintaining consistent ordering of button-related validations.Changelog and Versioning:
CHANGELOG.mddocuments the new rule under[2.2.3] - 2026-05-13with a detailed technical explanation of the WordPress save-function contract that the rule enforces.bin/pt-cliis updated from2.0.0to2.2.3, aligning the runtime version string with the release history tracked in the changelog.Files Changed:
CHANGELOG.md(Modified)bin/pt-cli(Modified)src/Compliance/Rules/BaseRules.php(Modified)