Add custom taxonomy support to Press This panel#150
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
Custom taxonomies registered for the post type now show up in the Press This sidebar, next to Categories and Tags. Hierarchical taxonomies get a checkbox tree like Categories, flat ones get a token field with autocomplete like Tags. Only taxonomies with show_ui enabled and that the current user can assign terms for are shown, and the same checks apply again on save so a request can't sneak terms in for a taxonomy that was never exposed to the panel. Category and post_tag keep going through their existing dedicated handling either way. Added a press_this_taxonomies filter so sites can add or remove taxonomies from the panel. Fixes WordPress#9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Custom taxonomies registered for the post type now show up in the Press This panel, alongside Categories and Tags. Previously only Category and Tags were ever shown, even if a site had other taxonomies registered.
Fixes #9
Changes
class-wp-press-this-plugin.php
Before:
After:
Why: Category and Tags keep their own dedicated panels, but every other registered taxonomy is now enumerated and sent to the editor, gated the same way Category/Tags already were (registration + capability).
press-this-plugin.php
Before:
// REST /save only ever accepted 'categories' and 'tags' paramsAfter:
Why: Needed a generic way to save terms for an arbitrary taxonomy, with the same gating applied on save as on read, so a taxonomy hidden from the panel can't be written to by crafting a request by hand.
src/components/TaxonomyPanel.js (new)
New component that renders one panel per custom taxonomy: a checkbox tree for hierarchical taxonomies (same interaction as the existing Category panel), or a token field for flat ones (same interaction as Tags).
src/components/PressThisEditor.js, src/App.js
Wired the new
taxonomiesdata through, addedtaxonomyTermsstate per taxonomy, included it in the save payload.Testing
Test 1: Hierarchical custom taxonomy
post(e.g.genre) with some terms.Result: post saved with the selected term.
Test 2: Flat custom taxonomy
post(e.g.rating).Result: term is created and assigned to the post.
Test 3: Gating
show_ui => false, or as a user withoutassign_termscapability for a taxonomy.Result: panel doesn't show, and a hand-crafted REST request with that taxonomy in
tax_inputis silently ignored (no error, term not saved).Test 4: Category/Tags unaffected
Result: Category and Tags panels behave exactly as before.
Ran the full PHPUnit and Jest suites plus PHPCS/ESLint, all green.