Skip to content

Commit f2f6af2

Browse files
authored
Fix Plugin/Theme header detection in PHP docblocks (#103)
## Summary `detectPluginHeaderFromPhpFile` and `parsePluginHeader` failed on standard WordPress plugin headers because the regex required only leading whitespace before the label: ```js /^\s*Plugin Name:\s*(.+)\s*$/im ``` A typical header line is ` * Plugin Name: Foo` — the `*` is not whitespace — so detection returned `null` / `count: 0` for every normal plugin. ### Before ```js contents.match(/^\s*Plugin Name:\s*(.+)\s*$/im) // Theme Name similarly new RegExp(`^\\s*${label}:\\s*(.+)\\s*$`, "im") ``` ### After ```js contents.match(/^\s*\*?\s*Plugin Name:\s*(.+)\s*$/im) contents.match(/^\s*\*?\s*Theme Name:\s*(.+)\s*$/im) new RegExp(`^\\s*\\*?\\s*${label}:\\s*(.+)\\s*$`, "im") ``` Optional docblock star keeps bare `Plugin Name:` / `Theme Name:` lines working (e.g. theme `style.css`). ## Files - `skills/wp-project-triage/scripts/detect_wp_project.mjs` - `skills/wp-plugin-development/scripts/detect_plugins.mjs` ## Verification (local fixtures) Against a docblock-style plugin (` * Plugin Name: WP Hello Plugin`): - `detect_wp_project` → `primary: "wp-plugin"`, `detectedPluginName: "WP Hello Plugin"` - `detect_plugins` → `count: 1` Against empty non-WP dir: still `unknown` / `count: 0`. Against block theme fixture: still `wp-block-theme` with `detectedThemeName` set.
1 parent ad58e37 commit f2f6af2

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎skills/wp-plugin-development/scripts/detect_plugins.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function parsePluginHeader(contents) {
7878
["Domain Path", "domainPath"],
7979
];
8080
for (const [label, key] of pairs) {
81-
const m = contents.match(new RegExp(`^\\s*${label}:\\s*(.+)\\s*$`, "im"));
81+
const m = contents.match(new RegExp(`^\\s*\\*?\\s*${label}:\\s*(.+)\\s*$`, "im"));
8282
if (m) header[key] = m[1].trim();
8383
}
8484
if (!header.name) return null;

‎skills/wp-project-triage/scripts/detect_wp_project.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ function findFilesRecursive(repoRoot, predicate, { maxFiles = 6000, maxDepth = 8
124124
function detectPluginHeaderFromPhpFile(filePath) {
125125
const contents = readFileSafe(filePath, 128 * 1024);
126126
if (!contents) return null;
127-
const headerMatch = contents.match(/^\s*Plugin Name:\s*(.+)\s*$/im);
127+
const headerMatch = contents.match(/^\s*\*?\s*Plugin Name:\s*(.+)\s*$/im);
128128
if (!headerMatch) return null;
129129
return headerMatch[1].trim();
130130
}
131131

132132
function detectThemeHeaderFromStyleCss(filePath) {
133133
const contents = readFileSafe(filePath, 128 * 1024);
134134
if (!contents) return null;
135-
const headerMatch = contents.match(/^\s*Theme Name:\s*(.+)\s*$/im);
135+
const headerMatch = contents.match(/^\s*\*?\s*Theme Name:\s*(.+)\s*$/im);
136136
if (!headerMatch) return null;
137137
return headerMatch[1].trim();
138138
}

0 commit comments

Comments
 (0)