Skip to content

fix(campaigns): guard against null taxonomy entries in prompt descriptions#4632

Draft
jason10lee wants to merge 2 commits into
trunkfrom
fix/campaigns-null-tags
Draft

fix(campaigns): guard against null taxonomy entries in prompt descriptions#4632
jason10lee wants to merge 2 commits into
trunkfrom
fix/campaigns-null-tags

Conversation

@jason10lee
Copy link
Copy Markdown
Contributor

@jason10lee jason10lee commented Apr 6, 2026

Changes proposed

Guards promptDescription() and warningForPopup() in utils.js against null/non-array taxonomy data (tags, categories, campaign_groups) that causes the Campaigns admin page to crash with TypeError: Cannot read properties of null (reading 'name').

Uses Array.isArray() + .filter(Boolean) to handle both false values from PHP's get_the_tags()/get_the_terms() and null entries from stale object cache.

How to test

  1. Navigate to Audience > Campaigns — page should load normally
  2. Add a mu-plugin to inject null tags:
    add_filter( 'get_the_tags', function( $terms ) {
        if ( is_array( $terms ) ) {
            $terms[] = null;
        }
        return $terms;
    } );
  3. Reload Campaigns page — should still render without errors
  4. Check browser console — no TypeError about null .name

Related

NPPM-2729: Campaigns admin page crashes when tag data contains null entries

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and tags to safe arrays using Array.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.

@jason10lee
Copy link
Copy Markdown
Contributor Author

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.

@jason10lee
Copy link
Copy Markdown
Contributor Author

jason10lee commented May 27, 2026

Spotted that warningForPopup() is probably similarly affected, copied the fix over to it, and then just refactored because that's just way too many repeats. Added tests, too, because why not while we're in there?

So...the scope's creeped, but for a good cause.

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.

2 participants