Move the gate's ABSPATH guard into the 50 lines Plugin Check reads - #11
Merged
Conversation
The listing check has been failing on one file, and the message it prints is misleading: "PHP file should prevent direct access." The file did prevent direct access. The guard was on line 56. Plugin Check's Direct_File_Access_Check looks for the guard in the first 50 lines of a file and nowhere else. In class-payment-integrity-gate.php a 39-line docblock and a twelve-line `use` block had pushed the guard past that window, so the check concluded there was none, and — because the file plainly contains executable code — reported it as an error rather than waiving it. That is the whole failure. Every other shipped PHP file carries its guard at line 44 or earlier, which is why exactly one file was ever reported. The two previous attempts at this missed it because they reasoned from the message instead of from the tool: uninstall.php is skipped by this check entirely, and index.php was already inside the window. So the guard moves up, directly under the namespace declaration and above the imports, which is where the rest of the plugin puts it anyway. Nothing about the protection changes; it is now somewhere the reviewer's tool can see it. DirectAccessGuardTest makes the position a tested property rather than a thing to remember: every shipped PHP file must carry an ABSPATH (or WPINC) guard, and it must appear within the first 50 lines. A vacuity check fails the suite if the file scan ever stops finding files. The failure message says what to do about it, because a line-number budget is not self-explanatory. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XCeph8upkSsVYUiSy2fRGF
Shubochandrosarker
marked this pull request as ready for review
August 12, 2026 19:02
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.
What this changes
CI / WordPress Plugin Checkhas been red onmainwith one error —missing_direct_file_access_protection, "PHP file should prevent direct access" — and the message is misleading, because the file did prevent direct access. Plugin Check'sDirect_File_Access_Checkreads a file's first 50 lines when it looks for the guard and nowhere else; inincludes/payments/class-payment-integrity-gate.phpa 39-line docblock plus a twelve-lineuseblock had pushed the guard to line 56. The check therefore concluded there was no guard, and because the file plainly contains executable code it reported an error instead of waiving it. After this PR the guard sits directly under thenamespacedeclaration and above the imports — where the rest of the plugin already puts it — at line 46. The protection itself is unchanged; it is now somewhere the reviewer's tool can see it.Closes #
Type
Rules touched
The change is the position of a
defined( 'ABSPATH' )guard within one file, plus a new test. No runtime behaviour, no payment logic, no schema.Multi-edit checklist
Documentation
tests/unit/DirectAccessGuardTest.php.What I ran
The last one is the audit that identified the fault: the gate was the only shipped file whose guard fell outside the window, which is why exactly one file was ever reported.
What I did NOT test
Plugin Check itself was never run locally. wp-env needs Docker and network access to
api.wordpress.organddownloads.wordpress.org, both blocked in this environment, so the only proof this fixes the job is the CI run on this PR. What I did instead was readDirect_File_Access_Checkfrom the plugin-check source and port its logic locally to reason about it — useful for finding the 50-line window, but not a substitute for the real run.Two earlier attempts at this failed because they reasoned from the error message rather than from the tool:
uninstall.phpis skipped by this check entirely, andindex.phpwas already inside the window. Neither was ever the cause.Risk and rollback
Generated by Claude Code