Skip to content

Add the trio core backports' show_in_rest REST-visibility flag - #15

Merged
nikmclaughlin merged 2 commits into
mainfrom
add/trio-show-in-rest
Nov 10, 2026
Merged

nikmclaughlin merged 2 commits into
mainfrom
add/trio-show-in-rest

Conversation

@nikmclaughlin

@nikmclaughlin nikmclaughlin commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What?

Adds 'show_in_rest' => true to the ability_meta() of the three tier-core backports — core/content-query (src/Content/Content_Query.php), core/settings-get (src/Settings/Settings_Get.php), core/users-query (src/Users/Users_Query.php) — each under a // Package: marker comment.

Why?

Core's WP_Ability only seeds meta.show_in_rest from meta.public since WordPress 7.1, and core's REST abilities routes (abilities/v1 list + run) hard-require the flag. The backports serve WordPress 6.9+, where no seeding happens, so the core-verbatim trio would silently vanish from REST on 6.9–7.0.x hosts. The AI plugin's own synced copies carry the same accommodation with a // Plugin: marker; this makes it once, in the package (§10.2, resolved Option A, decided 2026-11-06 — not to be relitigated). Full rationale + spec: PLAN-ai-plugin-poc.md §7.0, §10.2, §10.7, §11 step 1. On 7.1+ the public-seeding makes the explicit flag redundant but harmless — and both wp-env suites prove the registered meta is show_in_rest === true either way (seeded on trunk, explicit on stable).

How?

  • Three meta edits (+12/−3 lines each; public stays true; no other ability touched — the other 15 set show_in_rest already).
  • tools/coreify.php: one narrowly-scoped const, PKG_META_ACCOMMODATIONS (map of meta key → marker-comment lines, global across profiles — every tier-core backport has the same 6.9+ floor), teaches the round-trip tolerance exactly this one marked divergence, symmetrically:
    • --reverse injects the key + marker lines when emitting the package shape's ability_meta(), only when the fixture's meta lacks the key (a fixture that already carries it is carried through verbatim, never duplicated), so regenerated backports keep the flag and stay semantically identical to the shipped files (the mB side of the gate).
    • forward drops exactly the mapped key (plus marker-comment lines) when unwrapping ability_meta() into core-shaped registration args, so the regenerated core text stays semantically identical to the fixture (the mA side). No wildcard dropping of anything else.
    • Strict markers: the marker is the audit trail — a mapped key found without the const's exact comment lines fails the forward path loudly (coreify: pkg-meta drop: ability_meta() carries the accommodated key 'show_in_rest' without PKG_META_ACCOMMODATIONS's exact marker comment lines ...), so the shipped files and the const change together. (The mB semdiff still skips comments by design, unchanged.)
  • Tests: PR Add meta.mcp.public to the media and terms abilities for MCP exposure #12's pattern mirrored for the trio — an exact-shape assertion pinning meta.show_in_rest === true (fails on absent/type changes) plus public-stays-true via the accessor, in tests/Abilities/ContentQueryTest.php, tests/Abilities/SettingsGetTest.php, tests/Abilities/UsersQueryTest.php (expansion only — zero assertion deletions).
  • CHANGELOG.md Unreleased entry (house style).

Preflight findings (§10.7 trio sync-parity gate)

The three WordPress/ai develop copies (synced at core r65075 / r65002 / r64346) were diffed against this package's trunk fixtures (plugin copy vs fixture, not vs the package shape). Confirmed within the brief's accepted-delta set:

  1. Text domain 'ai' vs default — all three copies.
  2. Override vs stand-down: no longer a divergence — the current plugin copies stand down exactly like ours (wp_has_ability( ... ) → return, with a // Plugin: marker: "so core's version and its security fixes stay in effect"); no wp_unregister_ability() anywhere in the trio. (The known override delta has already converged plugin-side.)
  3. Category declaration priority (plugin: wp_abilities_api_categories_init at priority 11 from its own class; ours: Registrar priority 20) and the explicit show_in_rest flag (both sides now, // Plugin: vs // Package: markers — this PR extends the package's marker to the trio metas).
  4. Structural scaffolding — class wrapper + init() hooks + namespaced ABSPATH guard vs the Abstract_Core_Ability authoring surface; the plugin's array_all()/array_any() loop replacements and phpcs:ignore/@phpstan-ignore annotations are plugin-stubs artifacts, non-behavioral.

Known intentional divergence, confirmed: the plugin's Settings (r64346 sync) deliberately omits core r64500's required_capabilities => manage_options for pre-7.2 safety and keeps its permission callback; ours carries r64500 core-verbatim with Abstract_Core_Ability capability-floor handling for pre-7.2 hosts — ours being more faithful, not drift. Our settings fixture is additionally byte-identical to today's trunk (the plugin copy is intentionally behind).

⚠️ Known staleness — outside the flag's scope; tracked as PLAN-ai-plugin-poc.md §7.0b (a separate stacked trunk-sync PR, to resolve before the ai PoC pins its ref): the plugin copies are synced to trunk revisions newer than our fixtures (fixtures refreshed 2026-10-20, re-verified 2026-10-23), verified by diffing today's wordpress-develop trunk against both sides (trunk matches the plugin copies; our fixtures differ):

  • core/content-query — trunk (r65075-era) reworked author visibility: get_visible_author() memoized per query via a new $visible_authors property, an edit_user permission branch, and count_user_posts() restricted to post types filtered by show_in_abilities + viewability. Our fixture and src/Content/Content_Query.php still carry the older get_author_by_slug() gating (is_user_member_of_blog + edit_others_posts, count over all viewable post types).
  • core/users-query — trunk (r65002-era) turned the registered output field into a dotted registered.site/registered.gmt object and added the dotted-field projection machinery (get_field_paths(), is_field_requested() via rest_is_field_included(), and the fields input enum of those paths); our fixture and src/Users/Users_Query.php still have the flat registered_date field. (core/settings-get is current — no staleness.)

These are real user-visible behaviors missing from the package's content/users backports. They are not a regression caused by this PR (which only adds one meta key), and bundling a core re-sync here would break the one-PR-one-purpose line, so they are flagged for the follow-up instead. The preflight enumeration in the plan (§10.7 cites the content sync as r64907) predates the plugin's current r65075 sync.

Housekeeping note (resolved 2026-11-06): PR #12's description originally cited a CHANGELOG.md entry its branch lacked; the claim was dropped from that description — the entry will land on the branch together with the flag-level resolution.

⚠️ Stacked on #12 (add/mcp-public-meta) — merge order belongs to the team

This PR is stacked on #12 (00d65cf) and is not to be merged until the team resolves #12's open question; merging is a human/team call. The stack keeps the package's head carrying all 18 abilities plus both meta accommodations. #12's own SHA is immutable, so the MCP adapter PoC's pin (WordPress/mcp-adapter #430 → 00d65cf) is unaffected either way.

Open question (non-blocking, same class as #12's)

PKG_META_ACCOMMODATIONS is global across profiles, and forward drops the mapped keys from any profiled meta even if a future fixture itself starts carrying show_in_rest (at which point mA fails loudly — a conscious fix: move the key out of the const for that profile, or special-case). Acceptable for the three tier-core profiles per §10.2; the team may prefer a per-profile accommodation map later.

Use of AI tools

Tool(s): goose (agent) via the Solo orchestration harness. Model(s): glm-5.3-flash:cloud. Used for: implementation, tests, gate runs, and this description's drafting basis (plan-driven per PLAN-ai-plugin-poc.md §7.0; worker brief tools/out/worker-a-brief.md). Reviewed and edited by the committer.

Testing Instructions

  1. composer run lint:phpcs && composer run lint:phpstan && composer run verify:manifest && composer run verify:coreify — all clean (verify:coreify PASS on all three pairs; round-trip invariant holds).
  2. PHPUnit on both wp-env environments, one at a time:
    • npx @wordpress/env start --config=.wp-env.stable.json --update && npx @wordpress/env run tests-cli --config=.wp-env.stable.json bash -c "cd wp-content/plugins/wordpress-abilities && vendor/bin/phpunit"
    • npx @wordpress/env start --config=.wp-env.trunk.json --update && npx @wordpress/env run tests-cli --config=.wp-env.trunk.json bash -c "cd wp-content/plugins/wordpress-abilities && vendor/bin/phpunit"
    • Full suite passes on both (284 tests); the new trio meta assertions exercise both paths of the flag (explicit on stable, core's public-seeding on trunk). One pre-existing upstream-faithful cast warning, unchanged by this diff.

Changelog entries

Added (CHANGELOG.md): the show_in_rest exposure flag on the three tier-core backports — REST exposure on every supported WordPress via an explicit, marker-verified meta accommodation, tolerated exactly by the coreify round-trip gate.

PLAN-mcp-adapter-poc.md step 1.5 (sec. 1 resolution, sec. 4.0): the 8 media/terms
abilities — wp/media-query, wp/media-upload, wp/media-update, wp/media-delete,
wp/terms-query, wp/term-create, wp/term-update, wp/term-delete — did not carry
the public meta, so the MCP adapter's McpAbilityExposure falls back to
meta.public and excludes them from the MCP surface. This adds the MCP-specific
flag mcp => array( public => true ) to their ability_meta(), which
McpAbilityExposure checks first, without changing their high-level publicness
(no public key added) — the team decides between the mcp flag and full
meta.public before this lands on the package's main.

annotations/show_in_rest and every other meta key are untouched; no other
ability changes. The Registrar's Gate-6 public_only probe reads the ability's
own public meta only — the flag is additive there.

Tests: the registered-once tests of the 8 abilities (media-query/upload/
update/delete, terms-query, and the term-writes contract test) each now also
assert the exact mcp meta shape ( array( public => true ) ) and that the
high-level public meta is unchanged (get_meta_item( 'public', false ) ===
false). No assertions were deleted.
PLAN-ai-plugin-poc.md sec. 7.0 (sec. 10.2 resolution, Option A): core/content-query,
core/settings-get and core/users-query gain 'show_in_rest' => true in ability_meta()
under a // Package: marker, so the abilities stay exposed over core's REST abilities
routes on every supported WordPress (6.9+) — core's own registration omits the flag
and relies on meta.public seeding it, which WordPress 7.1+ only does. On 7.1+ the
seeding makes the flag redundant but harmless. The same accommodation the AI plugin's
synced copies carry with their // Plugin: marker, made once in the package.

tools/coreify.php tolerates exactly this marked line and nothing more, symmetrically:
a narrow PKG_META_ACCOMMODATIONS map (meta key => marker-comment lines) makes
--reverse re-inject the flag (plus markers) into regenerated backports when the
fixture's meta lacks it, and forward drop it behind marker-verbatim checks when
unwrapping ability_meta() into core-shaped registration args — both semantic-diff
invariants of the check gate stay green, and a mapped key without the const's exact
markers fails the forward path loudly. The trio tests now pin meta.show_in_rest ===
true with the high-level public meta unchanged (PR #12's pattern).

Stacked on #12 (add/mcp-public-meta) so the ai PoC pins one integration ref.
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.

1 participant