From 7f4b5e6128920df8fb906f796563288b9d939196 Mon Sep 17 00:00:00 2001 From: Jason Chafin <1000543+Herm71@users.noreply.github.com> Date: Tue, 4 Aug 2026 11:54:09 -0700 Subject: [PATCH] fix: root template requires at __DIR__ and drop an unused template part The two taxonomy templates that compose from parts/ used bare relative requires, which resolved only via PHP's fallback to the calling file's directory. Rooting them at __DIR__ removes the reliance on that implicit lookup. Behavior is unchanged. Also removes lib/templates/parts/post-query.php. Nothing required it, and it queries postType "post" rather than "fund", so it could not have served these templates anyway. It shipped in the ZIP regardless, since lib/ is in the files array. Records the template composition split in ROADMAP section 4 as an open question: taxonomy-fund-type and taxonomy-fund-theme are 11 lines built from parts, while archive-fund, single-fund, taxonomy-area and taxonomy-keyword inline everything, and the two inlined taxonomy templates are near-identical to each other. Closes #134 Co-Authored-By: Claude Opus 5 (1M context) --- .github/copilot-instructions.md | 2 +- CLAUDE.md | 2 +- ROADMAP.md | 17 ++++++++++++++++- lib/templates/parts/post-query.php | 23 ----------------------- lib/templates/taxonomy-fund-theme.php | 4 ++-- lib/templates/taxonomy-fund-type.php | 4 ++-- 6 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 lib/templates/parts/post-query.php diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 3b03b31..462dedd 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -23,7 +23,7 @@ npm install # Install Node dev dependencies (@wordpress/scripts, stan - **Main file**: `plugin.php` - Entry point with template registration and ACF JSON configuration - **Functions**: Split into `lib/functions/general.php` (block bindings, search variations) and `lib/functions/settings.php` (admin settings page) - **Templates**: `lib/templates/` contains block-based templates for single funds and taxonomy archives -- **Template Parts**: `lib/templates/parts/` contains reusable template partials (`funds-search.php`, `post-query-funds.php`, `post-query.php`) +- **Template Parts**: `lib/templates/parts/` contains reusable template partials (`funds-search.php`, `post-query-funds.php`), pulled in with `__DIR__`-relative `require` - **Styles**: `lib/css/admin-settings.css` - Admin settings page styles - **ACF Configuration**: `acf-json/` directory stores Advanced Custom Fields configuration as JSON diff --git a/CLAUDE.md b/CLAUDE.md index 213411a..724eb0e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -60,7 +60,7 @@ So the same URL is computed by two different paths — `ucscgiving_fund_url()` f `lib/templates/*.php` are block-comment markup (``) with a couple of `require` statements, not PHP source. They are read through `ucscgiving_get_template_content()` (output buffering) and handed to `register_block_template()` in `plugin.php`. Two consequences: -- The `require 'parts/…'` calls inside them use **relative paths**, which resolve only because PHP falls back to the calling file's directory. Fragile — prefer `__DIR__` if touching them. +- The `require __DIR__ . '/parts/…'` calls inside them are explicitly rooted. Keep them that way — they were relative paths until #134, resolving only because PHP falls back to the calling file's directory. - PHPCS file-docblock sniffs are excluded for `lib/templates/` in `.phpcs.xml.dist`, since a file docblock there is meaningless. ## Conventions diff --git a/ROADMAP.md b/ROADMAP.md index 3b9f05d..823006c 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -92,7 +92,22 @@ The suite covers functions that are pure once WordPress is stubbed. Anything nee ## 4. Harden packaging and templates -- **Relative `require` in block templates.** `lib/templates/*.php` use `require 'parts/…'`, which resolves only because PHP falls back to the calling file's directory. Change to `__DIR__`-relative paths. Low effort, removes a latent break. +- ~~**Relative `require` in block templates.**~~ Done in [#134](https://github.com/ucsc/ucsc-giving-functionality/issues/134) — both calls are now `__DIR__`-rooted, and the unused `parts/post-query.php` was removed with them. +- **Template composition is split two ways.** *Needs a look before anything is decided.* + + | Template | Lines | Composition | + |---|---|---| + | `taxonomy-fund-type.php` | 11 | `require`s `parts/funds-search.php` + `parts/post-query-funds.php` | + | `taxonomy-fund-theme.php` | 11 | same | + | `taxonomy-area.php` | 74 | fully inlined | + | `taxonomy-keyword.php` | 74 | fully inlined | + | `archive-fund.php` | 74 | fully inlined | + | `single-fund.php` | 30 | fully inlined | + + The two inlined taxonomy templates are near-identical to each other, so there is real duplication: a change to the archive layout currently has to be made in both, and neither picks up edits to `parts/`. Converting them to the parts pattern would remove that, but it changes rendered markup and needs visual QA, so it is not a mechanical cleanup. + + Worth noting the two are entangled: the inlined templates are also the ones carrying the hardcoded production media ([#133](https://github.com/ucsc/ucsc-giving-functionality/issues/133)) and the unpinned template-part references ([#136](https://github.com/ucsc/ucsc-giving-functionality/issues/136)). Whoever picks up the composition question should look at all three together rather than in isolation. + - **Single URL-construction path.** `ucscgiving_fund_url()` (block binding) and `ucscgiving_link_filter()` (permalink) build the same URL independently. Extract one helper so they cannot diverge. Both now have characterization tests (§3), so the extraction can be made and shown to preserve behavior — this is the cheapest remaining item. ## 5. Maintenance diff --git a/lib/templates/parts/post-query.php b/lib/templates/parts/post-query.php deleted file mode 100644 index 799ccef..0000000 --- a/lib/templates/parts/post-query.php +++ /dev/null @@ -1,23 +0,0 @@ - -
- -
- - - - - - - -
- - - - - - - - - -
- \ No newline at end of file diff --git a/lib/templates/taxonomy-fund-theme.php b/lib/templates/taxonomy-fund-theme.php index 352a1bc..84cd391 100644 --- a/lib/templates/taxonomy-fund-theme.php +++ b/lib/templates/taxonomy-fund-theme.php @@ -4,8 +4,8 @@
- - + +
diff --git a/lib/templates/taxonomy-fund-type.php b/lib/templates/taxonomy-fund-type.php index 352a1bc..84cd391 100644 --- a/lib/templates/taxonomy-fund-type.php +++ b/lib/templates/taxonomy-fund-type.php @@ -4,8 +4,8 @@
- - + +