fix(campaigns): guard against null taxonomy entries in prompt descriptions#4632
fix(campaigns): guard against null taxonomy entries in prompt descriptions#4632jason10lee wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Audience → Campaigns wizard UI against malformed taxonomy data returned for prompts, preventing runtime crashes when taxonomy arrays contain false/null entries (e.g., from get_the_tags()/get_the_terms() or stale object cache).
Changes:
- Normalize
campaign_groups,categories, andtagsto safe arrays usingArray.isArray(...)with falsy-entry removal. - Update prompt description string-building to use the normalized taxonomy arrays.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
My only comment here as to the approach would be that maybe this fix happens too far down the tree: we own the plugin that's setting these variables, so this normalization could be happening there. Maybe the framing of the original Linear task determined the agent's choice of fix? Still, the fix works, and could serve as part of a broader belt-and-suspenders approach with a corresponding tweak to newspack-popups. |
|
Spotted that So...the scope's creeped, but for a good cause. |
Changes proposed
Guards
promptDescription()andwarningForPopup()inutils.jsagainst null/non-array taxonomy data (tags, categories, campaign_groups) that causes the Campaigns admin page to crash withTypeError: Cannot read properties of null (reading 'name').Uses
Array.isArray()+.filter(Boolean)to handle bothfalsevalues from PHP'sget_the_tags()/get_the_terms()and null entries from stale object cache.How to test
TypeErrorabout null.nameRelated
NPPM-2729: Campaigns admin page crashes when tag data contains null entries