Repository navigation
Port the wp/media-query ability from WordPress/ai PR #1098 - #5
Merged
Merged
Conversation
## What?
Adds `wp/media-query` to the package: a faithful port of the read-only media
query ability from WordPress/ai PR #1098 ("Add core/media-query ability",
author @jorgefilipecosta), incubating under the experimental tier's `wp/`
prefix. The PR's registration name is not adopted; no alias exists.
## Why?
Agents can read posts, users, and settings through abilities, but not the
media library. This package ports the ability so consumers get one canonical
copy, while the upstream proposal settles.
## How?
- **The ability:** `src/Media/Media_Query.php` mirrors the PR's class — label,
description, input/output schemas (a `oneOf` of single-item and collection
modes), annotations (`readonly`/`idempotent`, `open_world` false),
error codes, the global-post restore, and the PR's documented REST quirks —
on the package's `Abstract_Core_Ability` authoring surface, with the
`default` text domain and closures for the registered callbacks.
- **Naming and tier:** manifest entry `wp/media-query`, tier `experimental`,
`core_since: null` (flips when core lands it), proposal pointing at the
WordPress/ai PR.
- **Category:** the `media` ability category is package-authored (core trunk
registers no media category; nothing to copy verbatim) — declared through
the Registrar's existing single-sourced `Categories` table.
- **No polyfill:** every core function the ability reads (attachments plumbing,
`wp_get_original_image_path`, `wp_filesize`, the filename-search hook) long
predates the 6.9 support floor; `requires` stays empty.
- **RegistrarTest P8 generalization:** with a package-declared-only category
in the manifest, the opt-out and late-first-contact tests can no longer
assume a 7.2+ host provides every manifest category; both tests now observe
which manifest slugs the host lacks (no version sniffing), assert the loud
Gate-8 path for those, and restore their replayed windows so the
package-declared categories survive for the following suites.
### Use of AI Tools
AI assistance: Yes
Tool(s): goose (agent)
Model(s): provided via the harness
Used for: Implementation, tests, and docs. Reviewed and edited by the
committer.
## Testing Instructions
1. Load the package in a `wp_abilities_api_init` callback:
`( new WordPress\Abilities\Registrar )->register_all();`
2. `wp_get_ability( 'wp/media-query' )->execute( array( 'id' => <attachment_id> ) )`
returns the default fields (`id`, `date`, `slug`, `title_rendered`,
`alt_text`, `media_type`, `mime_type`, `source_url`); adding
`array( 'fields' => array( 'title_raw' ) )` requires edit access.
3. Collection mode: `execute( array( 'media_type' => 'image', 'per_page' => 2 ) )`
returns `media`/`total`/`total_pages`.
4. Logged-out callers are denied with `ability_invalid_permissions`; a status
the caller may not query reports `media_invalid_param`.
5. `composer run lint:phpcs && composer run lint:phpstan &&
composer run verify:manifest && composer run verify:coreify` and the
PHPUnit suite on both wp-env environments pass.
Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
This was referenced Oct 29, 2026
nikmclaughlin
added a commit
that referenced
this pull request
Oct 30, 2026
…Abilities from WordPress/ai PR #1104 (#7) ## What? Adds the three media write abilities to the package: a faithful port of WordPress/ai PR #1104 ("Add core/media-upload, core/media-update, and core/media-delete abilities", author @jorgefilipecosta), incubating under the experimental tier's `wp/` prefix on the shared `media` category and field projection of `wp/media-query` (PR #5). The PR's `core/media-*` registration names, gating, and unregister-core-copy wiring are not copied; no aliases exist. ## Why? Agents can read the media library through abilities (`wp/media-query`) but not write it. This package ports the three writes so consumers get one canonical copy while the upstream proposal settles. ## How? - **The abilities:** `src/Media/Abstract_Media_Write.php` (shared base) + `Media_Upload.php` / `Media_Update.php` / `Media_Delete.php` mirror the PR's logic — labels, descriptions, schemas (upload is a `oneOf` of base64-data and URL-branch; delete output is a `oneOf` of the trashed item and the `deleted`/`previous` pair), annotations (`open_world: true` on upload), error codes, the URL-sideload SSRF guard and download-size cap, the status / author / parent checks that name the refused field in the execute callback, and the global-post restoration — on the package's `Abstract_Core_Ability` authoring surface, with the `default` text domain and closures for the registered callbacks. Shared helpers are extracted verbatim from the package's `Media_Query` port with `private` relaxed to `protected`. - **Naming and tier:** manifest entries `wp/media-*`, tier `experimental`, `core_since: null` (flips when core lands them), proposal pointing at the WordPress/ai PR. - **No polyfill needed:** every core primitive the writes rely on (`wp_handle_sideload`, `wp_http_validate_url`, `MEDIA_TRASH`, the media-cap mapping) exists on the supported floor (WordPress 6.9+). - **Tests:** `MediaUploadTest` / `MediaUpdateTest` / `MediaDeleteTest` — Registrar-based, ported from the PR's integration tests: negative and positive checks on every permission path (upload_files, edit_post, publish floors), wrapped and URL transports, trash/force semantics with the media trash guard, gone-read field parity against the live media REST endpoint responses, and hook/globals hygiene. ## Use of AI tools Tool(s): goose (agent) Model(s): provided via the harness Used for: Implementation, tests, and docs. Reviewed and edited by the committer. ## Testing Instructions 1. Load the package in a `wp_abilities_api_init` callback: `( new WordPress\Abilities\Registrar )->register_all();` 2. `wp_get_ability( 'wp/media-upload' )->execute( array( 'data' => base64_encode( $bytes ), 'filename' => 'p.jpg' ) )` uploads the file and returns the item in the edit context (raw fields included when requested — the caller already had edit access to upload). 3. `wp_get_ability( 'wp/media-update' )->execute( array( 'id' => $id, 'title' => 'New title' ) )` updates fields (omitted fields keep their values); a status other than the attachment's current one is validated, so non-attachment statuses are rejected while `inherit` can be kept. 4. `wp_get_ability( 'wp/media-delete' )->execute( array( 'id' => $id ) )` trashes (requires `MEDIA_TRASH`, else `media_trash_not_supported`); `array( 'id' => $id, 'force' => true )` deletes the attachment and its files permanently and returns `deleted`/`previous`. 5. `composer run lint:phpcs && composer run lint:phpstan && composer run verify:manifest` and the PHPUnit suite on both wp-env environments (one at a time) pass. Co-authored-by: jorgefilipecosta <jorgefilipecosta@users.noreply.github.com>
This was referenced Nov 17, 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.
What?
Ports the read-only media query ability from WordPress/ai PR #1098 ("Add core/media-query ability", author @jorgefilipecosta) into this package as
wp/media-query, tier experimental.Follows the AI-plugin-port pattern of the content trio (#2/#3), not the tier-core backport pattern: the ability class is hand-authored on
Abstract_Core_Ability, and the PR'score/media-queryname is not adopted (no alias, per the rename protocol).Why?
Agents can read posts, users, and settings through abilities, but not the media library. The WordPress/ai plugin registers
core/media-querybehind its experiment flag; this package gives consumers one canonical, consumer-free copy while the upstream proposal settles. The experimental tier fits: the upstream ability is an open PR, not landed core, so the name and schema carry no promises yet (core_since: null).How?
src/Media/Media_Query.php(WordPress\Abilities\Media\Media_Query, final,extends Abstract_Core_Ability) — a faithful port of the PR's ability class:oneOfinput schema: one item byid, or a collection returning{ media, total, total_pages }.search,media_type,mime_type,parent,author,include,exclude,status; sortingorderby/order; pagingpage/per_page(max 100).fieldspicks the returned fields with the PR's lean default set;idis always returned;title/caption/descriptionflatten to*_raw/*_rendered; a raw field switches the request to the edit context (collections then list only editable items).excludeis ignored whenincludeis given; disallowed MIME types are ignored; password-protected items' generated captions stay gated while rendered descriptions do not; a missing item is denied like an unreadable one; a queryable-but-forbidden status reportsmedia_invalid_param(400) from the execute callback rather thanability_invalid_permissions.wpai_*filters, and the plugin's base class are not ported — the Registrar owns registration, the text domain isdefault, callbacks are closures, and no support-feature polyfill is needed (requiresstays empty; everything the ability reads predates WP 6.9).src/Manifest.php— entry'wp/media-query', tierTIER_EXPERIMENTAL,min_wp_version: 6.9,core_since: null,proposal: https://github.com/WordPress/ai/pull/1098.src/Categories.php— new package-authoredmediaability category"Abilities that retrieve or manage media items and attachments.". Core trunk'swp_register_core_ability_categories()registers no media category, so there is nothing to copy verbatim; the entry is styled like trunk's own registrations and carries an in-code note to replace it with core's strings should core land one. This is the first manifest category the host does not provide on any environment.tests/Abilities/MediaQueryTest.php— the per-ability contract suite in this repo's shape, ported from the PR'sMediaTest: schemas (input and output) asserted through the Registrar; permission negative and positive on every gate path (logged out, per-role visibility by status/parent, raw-field edit gates, hidden-from-REST denial, missing-item denial indistinguishable from unreadable); fail-closed on malformed/unknown input across 18 oneOf cases; execute against factory data — filters, string/CSV inputs, statuses, ordering rules (relevance/includeguards), pagination bounds, password gate, rendered-field filters, filesize metadata normalization, media-details sizes (skipped only when GD lacks JPEG), output-schema validation, global-post restore, and filter cleanup after a throwing title filter.tests/RegistrarTest.php— the two P8 tests (opt-out filter, late first contact) assumed every manifest category is host-provided, which is no longer true now that the manifest declares the host-lessmediacategory. Both generalize to observe which manifest slugs the host lacks (observed state, no version sniffing): the loud Gate-8 path is asserted for those slugs, per-ability registration branches on the host-ownedcontentcategory, and both tests now also replay their windows on the host-owned path so package-declared categories survive for the following suites. On stable (7.1.x) the behavior is unchanged.wp/), CHANGELOGAddedentry (experimental), and KNOWN-ISSUES "Ported-as-is PR behaviors" entries for the quirks above.Testing Instructions
All four local gates pass, and the PHPUnit suite passes on both wp-env environments:
Manual: register the package in a
wp_abilities_api_initcallback and runwp_get_ability( 'wp/media-query' )->execute( array( 'id' => ATTACHMENT_ID ) )as an editor (default fields) and as a subscriber (denied for others' drafts' attachments; raw fields need edit access). Collection mode returnsmedia/total/total_pages.Deviations from the source PR
wp/media-query+ experimental per the settled decision D5 (the PR'score/media-queryname is reserved for core adoption via the promotion path; no alias ships).contentand registered it as a fallback; the port uses the package-authoredmediacategory (see How).'ai'→default; callbacks are closures wrapping the ported methods (the PR'sprotected_title_format()filter callback keeps its array form for callback identity).get_input_schema()/get_output_schema()were renamed to ability-specific builders (get_media_query_input_schema()/get_media_query_output_schema()) to avoid colliding withWP_Ability's public getters; two@phpstan-ignores cover stored attachment metadata being looser than core's docblock shape (the PR's own tests pin strings/booleans infilesizemetadata).RegistrarTestP8 generalization (see How) — an existing-suite contract update required by the first host-less manifest category, not a change to the PR behavior.Changelog Entry
Use of AI Tools
AI assistance: Yes
Tool(s): goose (agent)
Model(s): provided via the harness
Used for: Implementation, tests, and docs. Reviewed and edited by the committer.
Co-authored-by: jorgefilipecosta jorgefilipecosta@users.noreply.github.com