Skip to content

fix(template-switching): hide inactive/archived/deleted/spam templates from customer grid#1129

Merged
superdav42 merged 1 commit intomainfrom
feature/template-switching-hide-unavailable
May 6, 2026
Merged

fix(template-switching): hide inactive/archived/deleted/spam templates from customer grid#1129
superdav42 merged 1 commit intomainfrom
feature/template-switching-hide-unavailable

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

wu_get_site_templates() only filters by wu_type = site_template. It does not exclude templates the network admin has flagged as unavailable. The customer-panel template-switching grid was therefore listing every template in the network regardless of those flags, including templates the admin had explicitly taken out of circulation.

Filter $sites in Template_Switching_Element::output() to keep only templates that satisfy all of:

  • is_active() === true (mirrors the inactive-only filter the signup field already applies in inc/checkout/signup-fields/class-signup-field-template-selection.php:349)
  • is_archived() === false
  • is_deleted() === false
  • is_spam() === false

Applied at the element level (rather than in wu_get_site_templates()) so we do not change behaviour for the network-admin template list or any other consumer that legitimately wants to see all templates.

Why

Customer report: "some templates that should not be available are still listed". After a network admin deactivates, archives, deletes, or spams a template, the template continued to appear in customers''' "Available Templates" grid on the template-switching page, even though it was no longer eligible for assignment.

Verification

Reproduced and confirmed fix in the local dev environment:

  1. As customer kpcust1 (current template = Pink, customer site 6), navigated to /wp-admin/admin.php?page=wu-template-switching.
  2. With Template Blue marked inactive (set_active(false)), confirmed Blue is removed from the grid.
  3. With Template Site marked archived (set_archived(true)), confirmed Site is removed from the grid.
  4. With both flags cleared, confirmed all three test templates appear (subject to the existing "exclude current template" filter).

Adds a regression test that creates active, inactive, archived, deleted, and spam templates, renders the element, and asserts the sites array embedded in the dynamic-template JSON (the grid is rendered client-side by Vue from this payload) contains only the fully-available template.

PHPCS clean (no new violations). PHPStan clean. Template_Switching_Element_Test 7/7 (25 assertions); broader tests/WP_Ultimo/UI/ suite 67/67 (149 assertions).

Files changed

  • inc/ui/class-template-switching-element.php — filter unavailable templates from $sites.
  • tests/WP_Ultimo/UI/Template_Switching_Element_Test.php — regression test for the availability filter.

…el grid

`wu_get_site_templates()` only filters by `wu_type = site_template`. It
does not exclude templates the network admin has flagged as unavailable
(inactive via `wu_active` meta, or archived/deleted/spam via the WP
`wp_blogs` flags). The customer-panel template-switching grid was
therefore listing every template in the network regardless of those
flags, including templates the admin had explicitly taken out of
circulation.

Filter `$sites` in `Template_Switching_Element::output()` to keep only
templates that satisfy all of:

- `is_active() === true` (mirrors the inactive-only filter the signup
  field already applies in inc/checkout/signup-fields/class-signup-field-template-selection.php:349)
- `is_archived() === false`
- `is_deleted() === false`
- `is_spam() === false`

Applied at the element level (rather than in `wu_get_site_templates()`)
so we don't change behaviour for the network-admin template list or any
other consumer that legitimately wants to see all templates.

Adds a regression test that creates active, inactive, archived,
deleted, and spam templates, renders the element, and asserts the
`sites` array embedded in the dynamic-template JSON (the grid is
rendered client-side by Vue from this payload) contains only the
active, fully-available template.

Reported by customer: 'some templates that should not be available are
still listed'.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 18 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa187bd6-8640-4a60-aebe-fbecbf6f3759

📥 Commits

Reviewing files that changed from the base of the PR and between e9448e1 and 19a64ab.

📒 Files selected for processing (2)
  • inc/ui/class-template-switching-element.php
  • tests/WP_Ultimo/UI/Template_Switching_Element_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/template-switching-hide-unavailable

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit 956cb1d into main May 6, 2026
11 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Performance Test Results

Performance test results for 218d8bb are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.80 MB 843.00 ms 164.50 ms (+5.50 ms / +3% ) 1052.50 ms 2018.00 ms (-58.00 ms / -3% ) 1928.30 ms (-46.00 ms / -2% ) 90.60 ms (-2.90 ms / -3% )
1 56 49.11 MB 962.50 ms 148.50 ms 1112.00 ms 2084.00 ms 2006.25 ms 81.70 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant