fix(template-switching): hide inactive/archived/deleted/spam templates from customer grid#1129
Conversation
…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'.
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🔨 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! Login credentials: |
|
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:
|
Summary
wu_get_site_templates()only filters bywu_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
$sitesinTemplate_Switching_Element::output()to keep only templates that satisfy all of:is_active() === true(mirrors the inactive-only filter the signup field already applies ininc/checkout/signup-fields/class-signup-field-template-selection.php:349)is_archived() === falseis_deleted() === falseis_spam() === falseApplied 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:
kpcust1(current template = Pink, customer site 6), navigated to/wp-admin/admin.php?page=wu-template-switching.set_active(false)), confirmed Blue is removed from the grid.set_archived(true)), confirmed Site is removed from the grid.Adds a regression test that creates active, inactive, archived, deleted, and spam templates, renders the element, and asserts the
sitesarray 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_Test7/7 (25 assertions); broadertests/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.