Repository navigation
🐛 fix(helpers): wpbones_modules() loads a module whose name ends with 'p' or 'h' - #144
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the module filename handling fix.
No open issues 🎉
What changed in this PR
Fixes #142 by correcting module filename handling in wpbones_modules() and its import() alias, so names ending in p or h load the intended file.
Changes:
- Replaces character-based trimming with
Str::finish()to ensure the.phpsuffix without truncating module names. - Adds five regression cases covering both helpers, including names with and without the extension.
| File | Description |
|---|---|
tests/Unit/ModulesHelperTest.php |
Tests module loading through both helpers for affected names and control cases. |
src/helpers.php |
Uses Str::finish() to construct the module filename correctly. |
Review effort: Balanced
… 'p' or 'h'
rtrim($file, '.php') strips any trailing '.', 'p' and 'h', so wpbones_modules('shop')
required plugin/modules/sho.php. A bytewise str_ends_with() check appends '.php' only
when it is missing (not Str::finish(): its /u regex turns a name that is not valid UTF-8
into '.php'). import() is an alias and is fixed with it.
Fixes #142
gfazioli
force-pushed
the
fix/modules-suffix
branch
from
November 23, 2026 10:40
7e57d80 to
0ba5e05
Compare
This was referenced Nov 23, 2026
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 was wrong
wpbones_modules()(and its aliasimport()) built the file name withrtrim($file, '.php') . '.php'. The second argument ofrtrim()is a set of characters, not a suffix, so every trailing.,pandhwas stripped:wpbones_modules('shop')requiredplugin/modules/sho.php,'graph'requiredgra.php,'Help.php'requiredHel.php, and each ended in a fatal "Failed opening required". Reported by @bardrop in #142. The bug dates back to the helper's introduction (47a7904, 1.8).What changed
src/helpers.php: a bytewisestr_ends_with($file, '.php')check appends.phponly when it is missing. NotStr::finish(): its/uregex makespreg_replace()returnnullon a name that is not valid UTF-8, and the helper would requireplugin/modules/.php(Codex review, round 1).tests/Unit/ModulesHelperTest.php: five names through bothwpbones_modules()andimport()(ends withp, ends withh,Help.php, and two that end with neither as guards).Proof
composer test: 373 tests, 1034 assertions, green. The 3 deprecations are the existingsetAccessible()calls inRestRouteTest/ViewAssetRoutingTeston local PHP 8.6, untouched here (CI runs 8.1–8.4). The new test on the unfixed helper: 3 of 5 cases error (shop,graph,Help.php).Live in WPKirk-Developing (
.claude/scripts/modules-live-smoke.sh: five modules written into the bench, the bench active alone, the calls run through WP-CLI,debug.logwatched):On v3.3.0 (63c99a7), red:
On this branch (542a67c, the same tree as the squashed head 0ba5e05), green:
Fixes #142