Repository navigation
feat(ci): audit rtgodam_before/after_attachment_lookup hook integrity - #2072
Conversation
Adds three static-analysis scripts under bin/ that guard the rtgodam_before_attachment_lookup / rtgodam_after_attachment_lookup hook pair against silent regressions, each checked against an accepted JSON baseline: - godam-wp-dam-hook-check.php: per-file hook-fire count regressions and before/after balance within a scope. - godam-attachment-access-coverage-check.php: new or growing attachment-access calls that aren't yet reviewed for hook coverage. - godam-interprocedural-leak-check.php: a self-wrapped function whose hook stays open across a call site elsewhere. Wires them into a new GitHub Actions workflow (wp_dam_hook_integrity_on_pull_request.yml) and into the local pre-commit hook via godam-hook-check-pre-commit.sh. Each script supports a `check` mode (default, used in CI) and an `update-baseline` mode (run locally after manually auditing new/changed code).
🔍 WordPress Plugin Check Report
📊 Report
❌ Errors (1)📁 readme.txt (1 error)
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
mismatched_plugin_name | Plugin name "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" is different from the name declared in plugin header "GoDAM". |
0 |
trademarked_term | The plugin name includes a restricted term. Your chosen plugin name - "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" - contains the restricted term "wordpress" which cannot be used at all in your plugin name. |
📁 composer.json (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
missing_composer_json_file | The "/vendor" directory using composer exists, but "composer.json" file is missing. |
📁 assets/build/blocks/godam-gallery-v2/render.php (2 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
15 |
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound | Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$inner_block_video_ids". |
23 |
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound | Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$inner_block_video_ids". |
📁 assets/build/css/main.css (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedStylesScope | This style is being loaded in all contexts. |
📁 assets/src/libs/analytics.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/08/25/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead. |
📁 assets/build/js/main.min.js (5 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
0 |
EnqueuedScriptsScope | This script is being loaded in all frontend contexts. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/2026/08/25/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
0 |
NonBlockingScripts.NoStrategy | This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds automated CI and local pre-commit guards to ensure GoDAM’s rtgodam_before_attachment_lookup / rtgodam_after_attachment_lookup hook pair remains present, balanced, and continues to cover attachment-access call sites as the codebase evolves.
Changes:
- Added three PHP CLI audit scripts (hook-count regression + balance, attachment-access coverage, and interprocedural leak detection) with baseline JSONs.
- Wired the checks into CI (new GitHub Actions workflow) and local development (Husky pre-commit + npm script).
- Updated repo hygiene (
.gitignorefor.idea/).
Reviewed changes
Copilot reviewed 3 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| package.json | Adds an npm script to run the three hook-integrity checks. |
| bin/godam-wp-dam-hook-check.php | New: baseline-backed wrap-count regression + within-scope before/after balance validation. |
| bin/godam-wp-dam-hook-baseline.json | New: accepted baseline for wrap/access counts. |
| bin/godam-interprocedural-leak-check.php | New: detects “self-wrapped callee + unwrapped follow-up” leak candidates, baseline-backed. |
| bin/godam-interprocedural-leak-baseline.json | New: accepted baseline container for leak candidates. |
| bin/godam-hook-check-pre-commit.sh | New: runs checks locally (only when relevant paths are staged). |
| bin/godam-attachment-access-coverage-check.php | New: flags attachment-access calls that occur with no “before” hook open, baseline-backed. |
| bin/godam-attachment-access-coverage-baseline.json | New: accepted baseline container for uncovered access call sites. |
| .husky/pre-commit | Runs hook-integrity checks after existing lint:staged. |
| .gitignore | Ignores JetBrains .idea/. |
| .github/workflows/wp_dam_hook_integrity_on_pull_request.yml | New CI workflow to run the three checks on PRs touching relevant paths. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
And will you be able to segregate whether the hooks are called in the context of Also, what if the developer tries to perform some post operation on a non-attachment post type where |
…ng godam_check_known_balance_exceptions
…e/adds-attachment-hooks-ci
rtBot
left a comment
There was a problem hiding this comment.
Code analysis identified issues
action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.
phpcs scanning turned up:
🚫 1 error
Powered by rtCamp's GitHub Actions Library
…e/adds-attachment-hooks-ci
…nt_lookup hooks around media (#2080) * feat: add rtgodam_before_attachment_lookup and rtgodam_after_attachment_lookup hooks around media * feat: add pending rtgodam_before_attachment_lookup and rtgodam_after_attachment_lookup hooks around media * fix: fixes core godam bugs * refactor: update before/after attachmet CI baseline * refactor: adds godam-coverage-ignore comments * refactor: update since version * feat: adds before/after media hook * refactor: adds godam-coverage-ignore comments * refactor: adds godam-coverage-ignore comments * feat: adds before/after media hook * feat: adds before/after media hook
…e/adds-attachment-hooks-ci
Summary
Adds automated CI + pre-commit checks that guard the
rtgodam_before_attachment_lookup/rtgodam_after_attachment_lookuphook pair against silent regressions. These hooks let a plugin that centralizes attachments across a multisite network (e.g. wp-dam) switch site context around every place GoDAM reads/writes attachment data directly, then switch back. GoDAM only fires them — nothing previously stopped a hook from quietly disappearing, or new attachment-access code from shipping without the wrapping it needs.What's included
bin/hook-check/balance.php— one check: everyrtgodam_before_attachment_lookupin a scope must reach a matchingrtgodam_after_attachment_lookupbefore the scope ends, and noaftermay fire with nothing open. Branch-aware around earlyreturn/throw/exit/die/wp_die()-style exits, so a guard clause that closes the wrap and returns early isn't a false alarm. Deliberately doesn't track whether a hook was removed or how much attachment-access code exists — that's a GitHub reviewer's job reading the diff, and a removed hook whose access call stays is caught directly (not historically) by the sibling coverage check below.bin/hook-check/coverage.php— a finer-grained, per-call-site pass: flags every attachment-access call (get_post_meta,wp_get_attachment_url, etc.) or attachment-shaped query pattern (WP_Query,get_posts,get_children, raw$wpdbqueries) that has no bracket open at that exact point, unless its argument is provably a pass-through of an already-safe value. Includes interprocedural call-graph tracing (arbitrary hops, with codebase-wide-uniqueness safeguards) so a parameter-sourced call covered only by a caller's caller doesn't false-positive.bin/hook-check/shared.php— tokenizer/scope-walking primitives shared by both scripts, plus thegodam-coverage-*directive parser (below). Extracted so the two scripts can't drift to different definitions of "what counts as firing a hook."godam-coverage-ignore/-disable/-enable/-ignore-filecomments — the only acceptance mechanism, replacing an earlier baseline-JSON +update-baselinedesign entirely. Mirrorsphpcs:ignore/disable/enable/ignoreFileminus a rule-code argument, since each checker only ever checks one thing:-disablewith no matching-enablebefore end of file is a hard error, not a silent "rest of the file is fine." No baseline files, noupdate-baselinemode — every run judges only the code and its own inline comments as they currently stand..github/workflows/wp_dam_hook_integrity_on_pull_request.yml— runs both checks in CI, scoped to PRs touchinginc/,admin/,assets/src/blocks/, or the checker scripts themselves.bin/hook-check/pre-commit.sh(wired into.husky/pre-commit) — runs the same two checks locally pre-commit, over the same path scope.package.json—godam-hooks:balance-check/godam-hooks:coverage-check, combined intolint:godam-hooksvianpm-run-all --continue-on-errorso a failure in one doesn't hide the other's findings.Notable detection fixes along the way
$wpdbquery referencing{$wpdb->posts}/{$wpdb->postmeta}via string interpolation previously went undetected — PHP's tokenizer splits that into separate$wpdb/->/poststokens with nowp_postssubstring for the old check to find.WP_Query/get_posts/get_childrencall whose arguments come from a separate helper function (e.g.new WP_Query( build_args() )) previously read as "not attachment-shaped" and wasn't flagged at all, since the post_type literal lives inside a callee the scan never looks into. Now defaults to flagging it, matching this tool's existing philosophy elsewhere: a false positive costs a one-line dismissal comment, a false negative is a silent gap.How it works
Single mode — the code plus its own inline
godam-coverage-*comments are the complete, self-contained source of truth:A real finding means either add the hook pair, or — if the call genuinely isn't centralization-relevant attachment data — add the matching inline comment with a reason, right at the call site.