Repository navigation
Add core/terms-query ability - #1084
muneeb-ashraf wants to merge 7 commits into
Conversation
Adds a read-only `core/terms-query` ability, gated behind the Custom Abilities experiment like `core/users-query` and `core/content-query`. It reads a single term by ID or by taxonomy and slug, or a paginated collection of one taxonomy's terms filtered by search, parent, attached post, emptiness, or included IDs, with `total` and `total_pages`. Permissions mirror WP_REST_Terms_Controller: only `show_in_rest` taxonomies, and terms of a post require the post to be publicly viewable or readable. Taxonomies that are not publicly viewable also require the taxonomy's `assign_terms` capability. See WordPress#1063. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1084 +/- ##
=============================================
+ Coverage 85.05% 85.36% +0.30%
- Complexity 4836 4952 +116
=============================================
Files 190 192 +2
Lines 17971 18402 +431
=============================================
+ Hits 15286 15708 +422
- Misses 2685 2694 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds tests for object and REST string input, direct execution of unreadable requests, malformed permission input, and the hook and category fallback, which the first round of tests left uncovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
Following the review on WordPress#1063, taxonomies are exposed to `core/terms-query` only when they opt in with `show_in_abilities`, the model `core/content-query` uses for post types. `show_in_rest` alone no longer exposes a taxonomy, since abilities skip the REST filters and callbacks that opt-in assumed. - Show_In_Abilities also marks `category` and `post_tag`, with the same explicit opt-out and core stand-down rules as post types. - The ability is not registered when no taxonomy is exposed. - Remove the `meta` field; term meta needs its own opt-in later. - Add `exclude`. - An invalid or unreadable `post` filter returns `terms_post_invalid_id` or `terms_forbidden_context`, like the REST terms controller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
Resolves the Gated_AbilitiesTest import conflict from the `core/settings-get` rename (WordPress#1087). Also marks Terms_Query as depending on core-object exposure, since `core/terms-query` now reads the `show_in_abilities` flag that Show_In_Abilities sets on `category` and `post_tag`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
Matches the `core/content-query` changes in WordPress#1122 and WordPress#1123: set the `public` meta flag added in WordPress 7.1, and write multi-line comments as block comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W6LxjEQnP4PPgXXvAM3M2F
|
@jorgefilipecosta @gziolo waiting on your reviews here |
|
@jorgefilipecosta works on the same ability in #1099. I will let him decide how to proceed. |
Stacked on #1004. Part of the follow-up on [jeffpaul's review](#1004 (comment)), items 5–7: the demo prompts ("Find a gap", "Audit content") need to list recent posts and filter them, and the workspace could only search by keyword. This adds the read tools those prompts need. ## What changed **`ai/search-content` lists and filters, not just searches.** - **`search` is optional.** Without it, the newest posts come first. - **New optional inputs:** - `orderby`: `relevance` or `date`. It defaults to relevance with a search term and to date without one. - `tax`: `{ taxonomy, terms }`, a public taxonomy and up to 20 term slugs or names. - `date_after` / `date_before`: `YYYY-MM-DD`, with both end days included. - `has_featured_image`: `true` or `false`. - **Each row also returns** `terms` (names keyed by taxonomy) and `has_featured_image`. - **Unchanged:** the per-post read check, the `examined`/`withheld` counts the transcript's trace reads, and the 20-post page cap. **A filter never widens the list.** Each of these is an error rather than being ignored: - a taxonomy the ability doesn't list (an unknown or private one); - a `tax` value that isn't an object; - a date that isn't a real day, such as `2026-02-31`. WP_Date_Query would otherwise read it as 1970-01-01. A term the taxonomy doesn't have matches no posts. Only publicly viewable taxonomies attached to a post type exposed to abilities can be filtered by or appear in a row's `terms`. A post has a featured image when its `_thumbnail_id` is a positive number, the same test `has_post_thumbnail()` uses for the row. Boolean and list inputs are read as typed values or as the strings a GET request carries. **New `ai/list-terms`.** - Lists the terms of those same public taxonomies, with each term's `name`, `slug` and published-post `count`. - Defaults to categories and tags. `orderby` is `name` or `count`, `hide_empty` defaults to true, and `per_page` is capped at 100. - It's read-only, not destructive, `open_world: false`, and requires an authenticated user. - It stands in until `core/terms-query` (#1099 / #1084) lands here, as the plan says. **Tool list and policy:** - Both abilities are on `Tool_Selector::DEFAULT_CANDIDATES`. - `core/settings-get`, the name WordPress 7.2 gives the settings reader, is added to `Tool_Policy::NEVER_ADMITTED` beside the old `core/read-settings` (plan KTD9). The gap was hidden only because core leaves out `open_world`. **Structure.** The filter clauses and taxonomy discovery live in a new `Search_Filters` class, shared by both abilities and resolved once per call. `docs/experiments/ai-workspace.md` covers the new inputs, the new ability and the never-admitted list. ## Tests PHPUnit, `Search_ContentTest`: - New: - "test_without_a_search_term_lists_newest_first" - "test_search_orders_by_relevance_unless_asked_for_date" - "test_filters_by_term_date_range_and_featured_image": the fixtures cover every combination of tag, year and thumbnail. - "test_date_range_includes_both_end_days" - "test_rows_carry_terms_and_featured_image" - "test_unknown_term_matches_no_posts" - "test_unknown_or_private_taxonomy_is_a_validation_error" (guard) - "test_execute_callback_refuses_an_unknown_taxonomy_without_schema_validation" - "test_listing_without_a_term_withholds_an_unreadable_post" - "test_an_impossible_date_is_refused" - "test_execute_callback_refuses_a_tax_filter_that_is_not_an_object" - "test_a_zero_thumbnail_id_counts_as_no_featured_image" - "test_private_taxonomy_terms_stay_off_rows" (guard) - Updated: - "test_input_schema_caps_per_page": `search` is no longer required. - "test_search_with_no_term_reports_no_withheld_count_when_a_post_type_was_dropped": comment wording only. PHPUnit, new `List_TermsTest`, 8 tests: - read-only and local annotations; - ordering by count; - leaving empty terms out by default; - categories and tags by default; - unknown and private taxonomies refused, through the schema and the callback; - the cap and total; - a logged-out request refused. PHPUnit, new `Search_Content_RestTest`, 2 guard tests: - "test_search_filters_are_honoured_from_a_query_string" - "test_list_terms_reads_its_inputs_from_a_query_string" PHPUnit, `Tool_PolicyTest`: - New: "test_settings_get_is_withheld_with_perfect_annotations". - Updated: "test_shipped_withheld_list_covers_the_sensitive_core_abilities". `Tool_PolicyTest` and `Tool_SelectorTest` now include `ai/list-terms` in the curated surface they assert against. What failed before the change: - On #1004's code, 11 search and policy tests fail, and `List_TermsTest` can't load without its class. - On the first commit (04bddc8), the impossible-date, non-object-`tax` and zero-thumbnail tests fail. - The tests marked "(guard)" pass on the earlier code too: - The unknown-taxonomy test passes because the old schema refused any `tax` input. - The two REST tests pass because, on WordPress 7.1.4, the abilities REST endpoint already converts query-string values to the schema's types. - The private-taxonomy test passes because the first commit already kept those terms off the row. Also run, on WordPress 7.1.4: - **Full PHPUnit suite:** 3091 tests passed, 57 skipped. After one final type-narrowing change for PHPStan, I re-ran only the 53 search and terms tests, which pass. - **e2e:** the `ai-workspace*` specs, plus the Abilities Explorer and custom abilities specs. 45 passed (Chromium). - **PHPStan:** no errors. - **phpcs:** - clean on the changed source files; - `Tool_PolicyTest` and `Tool_SelectorTest` have the same counts as the base; - the new `Search_Content_RestTest` has the same 3 errors as the existing `Content_RestTest`, from the same REST-server setup. Not covered: - The plan's live check isn't done. It asks the "Find a gap" and "Audit content" prompts, on a seeded site, to produce real tool calls that return the expected posts. That needs a live model, and the e2e suite mocks the provider. U10 covers the demo prompts end to end. - The 20-term cap on a `tax` filter has no test. - WordPress 7.0.x isn't covered. The REST coercion above was checked on 7.1.4 only, so the string-input parsing is what covers older cores. ## Code review ce-code-review ran at full depth on the first commit (04bddc8), run `20261105-103226-768518a0`. - **Reviewers:** correctness, security, adversarial, testing, maintainability, performance and API contract. - **Not run:** the cross-model pass, because no other provider's CLI is installed, so the adversarial lens ran in-process. There are no project standards files on this branch. - **Verdict:** "Ready with fixes". The validator confirmed three findings, all addressed in 54a0d3e: - **P1:** `Search_Content.php` grew from 1008 to 1276 lines. The filter logic moved into `Search_Filters`, and the file is now 1142 lines. The remaining growth is the new input and output schema. - **P2:** string `has_featured_image` and comma-separated `tax.terms` were dropped. Both are now read as typed values or strings. - The validator confirmed this in the code, for callers that skip schema validation. - Through REST on WordPress 7.1.4 it doesn't reproduce: the new REST tests pass on the first commit as well. - REST on 7.0.x wasn't measured. - **P3:** `ai/list-terms` ignored string `hide_empty` and `taxonomy`. Fixed the same way. - **Residual risks the review kept:** all addressed in 54a0d3e: - duplicated taxonomy discovery; - per-row recomputation; - impossible dates; - a non-object `tax`; - the featured-image filter and row flag disagreeing on `0`. One more: the `core/settings-get` name couldn't be checked against the local wordpress-develop checkout. It is the name this plugin's 1.5.0 sync with WordPress 7.2 uses. AI assistance: Yes. Tool(s): Claude Code (Claude Opus 5.5). Used for: implementing the change and its tests, which I reviewed. I've reviewed the changes, understand them and can explain them under review. They have all been tested locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- wp-playground-preview:start --> <a href="https://playground.wordpress.net?blueprint-url=data:application/json,%7B%22preferredVersions%22%3A%7B%22wp%22%3A%22latest%22%7D%2C%22login%22%3Atrue%2C%22landingPage%22%3A%22%2Fwp-admin%2Fadmin.php%3Fpage%3Dai-wp-admin%22%2C%22steps%22%3A%5B%7B%22step%22%3A%22installPlugin%22%2C%22pluginData%22%3A%7B%22resource%22%3A%22url%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.life-white.uk%2FWordPress%2Fai%2Freleases%2Fdownload%2Fci-artifacts%2Fpr-1296-54a0d3ecca1a243cad855c3f65fbfe074dd5b46b.zip%22%7D%7D%5D%7D" target="_blank" rel="noopener noreferrer"> <img src="https://raw.githubusercontent.com/adamziel/playground-preview/refs/heads/trunk/assets/playground-preview-button.svg" alt="Open WordPress Playground Preview" width="220" height="57" /> </a> <!-- wp-playground-preview:end --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collections now default hide_empty to true, so a listing returns terms in use. A post's own terms keep the old default, since they can have a zero count while the post is unpublished. Only a show_in_abilities value of true exposes a taxonomy, matching how develop now normalizes post types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Closing in favor of WordPress/abilities#10. |
What?
Closes #1063
Adds a read-only
core/terms-queryability, so agents and MCP clients can see which categories, tags, and other terms exist without guessing names or falling back to REST.Why?
The 7.2 roadmap names taxonomies among the read-only resources to cover, and nothing in the current
core/*-queryset exposes terms. Agents that draft or classify content need the real term list.How?
Built on the
core/users-query/core/content-querypattern, and gated behind the Custom Abilities experiment in the same way (Gated\Terms_Query, added toGated_Abilities).Exposure follows the model agreed in #1063: a taxonomy is readable only when it opts in with
show_in_abilities, like post types forcore/content-query.show_in_restalone does not expose a taxonomy.Show_In_Abilitiesmarkscategoryandpost_tag(notpost_format), with the same rules as post types: an explicitfalseis respected, and the polyfill stands down once core declares the flag onWP_Taxonomy. With no exposed taxonomy, the ability is not registered.Modes (a
oneOf, so mixed arguments are rejected):id(optionaltaxonomymust match),taxonomy+slug,taxonomy, filtered bysearch,parent,post,hide_empty,include,exclude, withorderby/order,page/per_page(default 10, max 100), returningterms,total,total_pages.hide_emptydefaults totrue, so a listing returns terms in use; withpostit defaults tofalse, since a post's own terms can have a zero count while the post is unpublished.Fields:
id,name,slug,taxonomy,description,parent(hierarchical only, as in REST),count,link. The default set isid,name,slug,taxonomy,parent,count. Term meta is not exposed; it would need its own opt-in.Permissions:
show_in_abilities;postmirrorsWP_REST_Terms_Controller: an unknown post returnsterms_post_invalid_id(400), and a post that does not use the taxonomy or that the user cannot read returnsterms_forbidden_context.Apart from the
hide_emptydefault, the collection query followsWP_REST_Terms_Controller::get_items():parentonly applies to hierarchical taxonomies, the taxonomy's registeredargsare merged in unlesspostis set, and totals come fromwp_count_terms()with the same arguments.Not included: a
core/taxonomies-querycompanion. As noted on #1063, the exposed taxonomies are listed in the input schema.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Code and tests.
Testing Instructions
tests/Integration/Includes/Abilities/Terms/TermsTest.php(31 tests) covers the issue's acceptance list and the opt-in model: curated and opted-in custom taxonomies, ashow_in_rest-only taxonomy being denied, an explicit opt-out, no registration without exposed taxonomies, hierarchical listing withparent, terms for a public, a private, and a missing post (with the error codes),exclude, pagination totals,metabeing rejected, the REST string forms of inputs, thehide_emptydefaults, and rejection of mixed modes.Show_In_AbilitiesTesthas 6 new taxonomy tests.Both pass locally (single site and multisite). The full PHPUnit suite shows the same failures as
developand no new ones, and PHPCS and PHPStan are clean on the changed files.Manual check: enable the Custom Abilities experiment, then run
core/terms-queryfrom the Abilities Explorer with{"taxonomy":"category"}, or call it through the MCP Adapter.Changelog Entry
🤖 Generated with Claude Code