Skip to content

Commit e7e90b5

Browse files
authored
Merge pull request #9 from imagewize/fix/button-width-class-false-positive
fix: avoid false positive in button width check when wrapper div shares a line
2 parents 97f4cb6 + 5a758bb commit e7e90b5

3 files changed

Lines changed: 11 additions & 2 deletions

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

bin/pt-cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Imagewize\PtCli\Commands\Scaffold\StyleCreateCommand;
2222
use Imagewize\PtCli\Commands\TemplateCheckCommand;
2323
use Symfony\Component\Console\Application;
2424

25-
$application = new Application('pt-cli', '2.3.0');
25+
$application = new Application('pt-cli', '2.3.1');
2626
$application->add(new CheckCommand());
2727
$application->add(new TemplateCheckCommand());
2828
$application->add(new PatternCreateCommand());

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)