Skip to content

Fixed preserve unloaded post taxonomy selections - #1387

Merged
vytisbulkevicius merged 5 commits into
developmentfrom
bugfix/1385
Nov 19, 2026
Merged

vytisbulkevicius merged 5 commits into
developmentfrom
bugfix/1385

Conversation

@girishpanchal30

@girishpanchal30 girishpanchal30 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Saving an existing import without opening Map Content deleted its saved Post Taxonomy selections (categories, custom taxonomy terms and the Auto Categories / Item Categories markers).

Root cause: The Post Taxonomy multiselect is rendered empty and only gets its options via AJAX (update_taxonomy()) when Map Content is opened or the post type changes. An empty multiselect submits nothing, and since #1126 the save handler turned a missing import_post_term into '' and deleted the meta. So any save made before the selector loaded wiped the stored terms. This also happened when saving while the terms were still loading, or after the AJAX request failed.

Fix:

  • includes/views/import-metabox-edit.php: adds a disabled hidden input, feedzy_post_terms_loaded, next to the taxonomy selector.
  • includes/views/js/import-metabox-edit.js:
    • update_taxonomy() disables that input when it starts loading and enables it once the options are rendered.
    • Each taxonomy request gets a sequence number. A response superseded by a later post type change is ignored, so a late response can't render the wrong post type's terms or enable the flag.
    • The request now sends the saved selection (selected).
  • includes/admin/feedzy-rss-feeds-import.php:
    • save_feedzy_import_feed_meta() normalizes a missing import_post_term to '' only when feedzy_post_terms_loaded was posted. Otherwise the saved value is left untouched.
    • get_taxonomies() also returns saved terms that fall outside the feedzy_post_taxonomy_limit cap (999 per taxonomy by default). They are listed with their names and stay selected, so opening Map Content and saving no longer drops them. Only <taxonomy>_<id> values for the requested post type's taxonomies are used.

Deliberately clearing every term still works (#1126 behavior), because by then the selector has loaded and the flag is submitted. Abilities API / Pro import creation write the meta directly or always send the terms, so they are unaffected. Nonce and capability checks on the AJAX and save handlers are unchanged; the new selected input is sanitized and only matching integer term IDs are used.

Tests:

  • PHPUnit (tests/test-import.php):
    • test_save_keeps_post_terms_when_selector_not_loaded_1385: fails on development, passes with the fix.
    • test_save_clears_post_terms_when_selector_loaded_1385: guards the feat: improve taxonomy setting UI #1126 clearing behavior.
    • test_get_taxonomies_returns_saved_terms_past_limit: with the limit filtered to 1, a saved term past it is still returned with its name.
  • E2E (tests/e2e/specs/import.spec.js, Post Taxonomy):
    • Saving without opening Map Content keeps the term.
    • Removing every term after they load clears it.
    • Saving while a taxonomy reload is pending keeps the term.
    • A saved term past the taxonomy limit stays selected and saved (uses the new tests/e2e/mu-plugins/feedzy-e2e-taxonomy-limit.php).
    • A late response for a superseded post type is ignored.

Test instructions

Use Feedzy Lite with Pro active, so the Auto Categories option is available.

  • Go to Feedzy → Import Posts → Add New. Set a source, open Map Content, select a category and Auto Categories by keyword under Post Taxonomy, then save.
  • Reload the import's edit screen. Do not open Map Content. Change only the import title (or a General Feed Settings field) and save.
  • Open Map Content. The previously selected terms should still be there. Before this PR, Post Taxonomy was empty.
  • Repeat with a custom taxonomy term, if one is available.
  • Regression check: open Map Content, wait for the terms to load, remove every selected term, save, and reopen. Post Taxonomy should stay empty.
  • Regression check: change the Post Type, wait for its taxonomies to load, pick a term, save, and reopen. The new term should be saved.
  • Term limit: add add_filter( 'feedzy_post_taxonomy_limit', fn() => 1 ); (e.g. in a mu-plugin). Select a category that is not first alphabetically, save, reopen Map Content and save again. The category should still be listed and selected.

Check before Pull Request is ready:

Closes #1385.

@pirate-bot

pirate-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Plugin build for e5381d9 is ready 🛎️!

Note

You can preview the changes in the Playground

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes requested

Fix the stale taxonomy response path. An older response can enable the new flag, and the save then deletes the saved Post Taxonomy.

Validation details
  • Files reviewed: 4/4 changed files.
  • PHPUnit A/B run on WordPress 7.1.4 with PHP 8.3: both new tests pass at HEAD. At base, the "keeps" test fails on its assertion and the "clears" test passes. No run record was printed; the log is in the sandbox.
  • Real editor, Firefox and Chromium: a save without opening Map Content kept the terms. A save after a soft reload kept them too cd /workspace/checks/R3 && cat > save-flow2.js <<'EOF' // R3 rerun: settled flag state after reload, flag state at submi… (run R25, exit 0).
  • Real editor, Chromium race: post type post, options none, flag posted, term deleted cd /workspace/checks/R4 && sed -i 's|^const wp = (c) => execSync('wp ${c} ${WP} 2>&1', { encoding: .utf8. }).trim();|con… (run R30, exit 0).
  • Security: the new read runs after the existing nonce and edit_post checks.
Untested areas
  • The Pro plugin and external feedzy_save_fields listeners are not in the checkout.
  • Clearing every term in the browser was not run. The server side is covered by a PHPUnit test.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • includes/admin/feedzy-rss-feeds-import.php:1429 — unverified: Empty or truncated taxonomy responses can enable the loaded flag without restoring saved selections. Explore empty-taxonomy responses and saved terms beyond the 999 query limit, pa…

🤖 Automated review · run code-review-agent_6afafeccbbc751.76148677.


🤖 Review agent — review posted ✅ on 6a7e723f · changes requested · 2 findings · 39 min

Run code-review-agent_6afafeccbbc751.76148677 · trail

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes requested

The stale-response fix works, but a saved term beyond the 999-term limit is still deleted on save, and the loading-flag test gap remains open.

Validation details
  • Files reviewed: 4/4 changed files. The commit since the last review changes the taxonomy script and the e2e spec.
  • Playwright on WordPress 7.1.4, PHP 8.3, Chromium: the four new Post Taxonomy tests pass at HEAD (4 passed (19.5s), sandbox run R11).
  • With the previous script, the superseded post type test fails (1 failed, sandbox run R12).
  • With line 376 deleted, all four tests still pass (4 passed (16.7s), sandbox run R13).
  • PHPUnit A/B from run code-review-agent_6afafeccbbc751.76148677 is reused, not rerun. The PHP files are unchanged since then.
Untested areas
  • The save-handler request read was not re-audited. It is unchanged since the last review, which found it behind the nonce and capability checks.
  • The Pro plugin and external feedzy_save_fields listeners are not in the checkout.
  • An empty taxonomy response enables the flag. It can lose a term only if site code unlinks a taxonomy from the post type. No real setup was shown.

🤖 Automated review · run code-review-agent_6afbf98336fd54.87460832.


🤖 Review agent — review posted ✅ on df916193 · changes requested · 1 finding · 27 min

Run code-review-agent_6afbf98336fd54.87460832 · trail

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approved

The PR passes. Both earlier findings are fixed, and the new tests fail when their fixes are removed.

Validation details
  • Files reviewed: 6/6 changed files. The two commits since the last review change 5 of them.
  • Playwright on WordPress, PHP 8.3 and Chromium runs all Post Taxonomy tests at HEAD: cd /workspace/checks/R1 && export WP_BASE_URL=http://localhost:8080 WP_USERNAME=admin WP_PASSWORD=admin WP_ARTIFACTS_PAT… printed 5 passed (run R3).
  • Without the line that disables the loaded flag, the loading test fails: cd /workspace/checks/R1 && export WP_BASE_URL=http://localhost:8080 WP_USERNAME=admin WP_PASSWORD=admin WP_ARTIFACTS_PAT… printed Received: enabled (run R4).
  • Without the new saved-term query, the term limit test fails: cd /var/www/html && wp term delete category 6 2>&1|tail -1; wp term delete category 7 2>&1|tail -1; cd /workspace/checks… printed 1 failed (run R20).
  • Two saved categories past a limit of 1 stay listed, selected and saved: rm -rf /workspace/e2e-copy && mkdir -p /workspace/e2e-copy && cp -r /repo/tests/e2e/specs /repo/tests/e2e/utils.js /work… printed 1 passed (run R26).
  • The security pass found the new selected input behind the existing nonce and capability checks.
Untested areas
  • A loaded save in Lite still drops saved terms of a taxonomy that the post type no longer has. An empty taxonomy list also enables clearing. Base code did the same. No common setup reaches it.
  • The Pro plugin is not in the checkout.
  • PHP CodeSniffer and the JavaScript build were left to CI.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • includes/views/js/import-metabox-edit.js:481-487 — unverified: An empty taxonomy response skips restoration of ordinary terms, Pro custom tags and both category markers, but enables clearing. This confirms the carried concern’s destructive bra…
    • includes/views/import-metabox-edit.php:1073-1075 — unverified: An empty taxonomy response skips restoration of ordinary terms, Pro custom tags and both category markers, but enables clearing. This confirms the carried concern’s destructive bra…
    • includes/admin/feedzy-rss-feeds-import.php:726-727,756-778 — unverified: An empty taxonomy response skips restoration of ordinary terms, Pro custom tags and both category markers, but enables clearing. This confirms the carried concern’s destructive bra…
    • includes/admin/feedzy-rss-feeds-import.php:1431-1460 — unverified: Lite restores only returned taxonomy terms; the unmatched-value fallback requires Pro. A saved term belonging to another post type can therefore disappear. Missing deciding evidenc…
    • includes/views/js/import-metabox-edit.js:400-428,464-475 — unverified: Lite restores only returned taxonomy terms; the unmatched-value fallback requires Pro. A saved term belonging to another post type can therefore disappear. Missing deciding evidenc…
    • includes/views/js/import-metabox-edit.js:358-371 — unverified: The carried limit concern now has an include-query backfill for every matching saved ID. Final coverage, especially several saved values, depends on X1’s assigned request-shape che…

🤖 Automated review · run code-review-agent_6afc05055aca29.39815405.


🤖 Review agent — review posted ✅ on 6306c1c0 · approved · 0 findings · 26 min

Run code-review-agent_6afc05055aca29.39815405 · trail

@vytisbulkevicius
vytisbulkevicius merged commit 93788b9 into development Nov 19, 2026
10 checks passed
@vytisbulkevicius
vytisbulkevicius deleted the bugfix/1385 branch November 19, 2026 20:43
@pirate-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.2.17 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saving an import without opening Map Content clears Post Taxonomy selections

3 participants