feat(taxonomy): centralize term resolution with datamachine/resolve-term ability#89
Merged
chubes4 merged 4 commits intoExtra-Chill:mainfrom Feb 3, 2026
Conversation
…erm ability
Fixes the 'numeric category 11' bug by creating a single source of truth
for taxonomy term resolution.
## New Ability
- datamachine/resolve-term: Resolves terms by ID, name, or slug with
optional creation. All code paths now use this ability.
## Architecture
- ResolveTermAbility: Core ability with static helper for internal use
- TaxonomyAbilities: Facade registering all taxonomy abilities
- Additional CRUD abilities: get, create, update, delete taxonomy terms
## Updated Callers
- TaxonomyHandler.findOrCreateTerm() → uses ResolveTermAbility::resolve()
- AssignTaxonomyTerm.resolveTerm() → uses ResolveTermAbility::resolve()
- CreateTaxonomyTerm existence check → uses ResolveTermAbility::resolve()
- CreateTaxonomyTerm.resolveParentTerm() → uses ResolveTermAbility::resolve()
## Resolution Order (centralized)
1. If numeric → get_term() by ID
2. Try get_term_by('name')
3. Try get_term_by('slug')
4. If create=true → wp_insert_term()
No more drift. One fix applies everywhere.
- Register ResolveTermAbility on datamachine_register_abilities hook - Use execute_callback and permission_callback (match other abilities) - Use proper input_schema with type/properties/required structure - Replace local SYSTEM_TAXONOMIES with TaxonomyHandler::shouldSkipTaxonomy() - Update/Delete abilities now use ResolveTermAbility::resolve() - Remove duplicate resolveTerm methods from Update/Delete abilities
Contributor
Author
|
Addressed review feedback ( ResolveTermAbility registration:
Single source of truth:
Update/Delete abilities:
Ready for re-review. |
…tterns
- Add WP_Ability class existence check in constructor
- Use did_action('wp_abilities_api_init') pattern for registration
- Add 'meta' => ['show_in_rest' => true] for REST exposure
- Match pattern used in GetTaxonomyTermsAbility and other abilities
GetTaxonomyTermsAbility has optional taxonomy param - only call shouldSkipTaxonomy when taxonomy is non-empty to avoid TypeError.
This was referenced Apr 21, 2026
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
Fixes the numeric category bug (e.g., category '11' created instead of resolving to Spirituality).
Root Cause
Multiple code paths had their own term resolution logic:
TaxonomyHandler.findOrCreateTerm()- had the fix (ID/name/slug)CreateTaxonomyTermtool - only checked by name ❌AssignTaxonomyTermtool - had its own resolveTerm()When AI output
category: "11", the CreateTaxonomyTerm tool would:get_term_by('name', '11')→ not found (term 11 is named 'Spirituality')Solution
Single source of truth:
datamachine/resolve-termabilityResolution Order (centralized)
get_term()by IDget_term_by('name')get_term_by('slug')create=true→wp_insert_term()New Files
inc/Abilities/Taxonomy/ResolveTermAbility.php- Core abilityinc/Abilities/TaxonomyAbilities.php- FacadeUpdated Callers
All now use
ResolveTermAbility::resolve():TaxonomyHandler.findOrCreateTerm()AssignTaxonomyTerm.resolveTerm()CreateTaxonomyTermexistence checkCreateTaxonomyTerm.resolveParentTerm()Testing
With this change, if AI outputs
category: "11":ResolveTermAbility::resolve('11', 'category')is_numeric('11')→ trueget_term(11, 'category')→ returns Spirituality ✅No more drift. One fix applies everywhere.