Skip to content

Commit 3dde337

Browse files
committed
fix(compliance): avoid false positive on button width check when wp:button and wp-block-buttons share a line
checkButtonWidthClasses used str_contains($html, 'wp-block-button') which matched the plural wp-block-buttons wrapper div when it appears on the same line as the <!-- wp:button comment (correct compact inline formatting per Elayne CLAUDE.md). Replaced with a word-boundary regex so only the singular wp-block-button inner div triggers the class check.
1 parent 97f4cb6 commit 3dde337

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
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).
66

7+
## [2.3.1] - 2026-05-14
8+
9+
### Fixed
10+
11+
- `checkButtonWidthClasses`: false positive when `<!-- wp:button` appears on the same line as the outer `<div class="wp-block-buttons">` wrapper. The previous `str_contains` check matched `wp-block-buttons` as a substring of `wp-block-button`, incorrectly reporting missing `has-custom-width`/`wp-block-button__width-N` classes. Replaced with a word-boundary regex that distinguishes the singular `wp-block-button` (inner div) from the plural `wp-block-buttons` (wrapper).
12+
713
## [2.3.0] - 2026-05-14
814

915
### Added

src/Compliance/Rules/BaseRules.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,12 @@ private function checkButtonWidthClasses(string $content): array
262262
}
263263
$pct = (int) $m[1];
264264
// Scan current line and the next two for the HTML div.
265+
// Use a word-boundary match to distinguish wp-block-button (inner div)
266+
// from wp-block-buttons (wrapper div that may appear on the same line
267+
// as the <!-- wp:button comment when compact inline formatting is used).
265268
for ($j = $i; $j <= $i + 2 && $j < $total; $j++) {
266269
$html = $lines[$j];
267-
if (!str_contains($html, 'wp-block-button')) {
270+
if (!preg_match('/\bwp-block-button\b(?!s)/', $html)) {
268271
continue;
269272
}
270273
if (!str_contains($html, 'has-custom-width') || !str_contains($html, "wp-block-button__width-{$pct}")) {

0 commit comments

Comments
 (0)