Repository navigation
Port the media write abilities (wp/media-upload, wp/media-update, wp/media-delete) from WordPress/ai PR #1104 - #7
Merged
Conversation
…Abilities from WordPress/ai PR #1104
## 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 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?
Adds the three media write abilities to the package:
wp/media-upload,wp/media-update, andwp/media-delete— 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'swp/prefix (D5). The PR'score/media-*names, gating, and unregister-core-copy wiring are not copied; no aliases exist (D7).The writes build on the merged
wp/media-queryfield projection (PR #5): written attachments are answered through the same contract, in the edit context, and register under the package-authoredmediacategory (core trunk has no media category to copy).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 (plan item B2, decisions D2/D5).How?
src/Media/Abstract_Media_Write.php(shared base) +Media_Upload.php/Media_Update.php/Media_Delete.phpmirror the PR's logic — labels, descriptions, schemas (upload input is aoneOfof a base64-data branch and a URL branch; delete output is aoneOfof the trashed item and thedeleted/previouspair), annotations (open_world: truefor upload's URL sideload), 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 (because the Abilities API replaces permission-callback errors with a generic one), and the global-post restoration the upstream PR refactored into a helper — on the package'sAbstract_Core_Abilityauthoring surface, with thedefaulttext domain and closures for the registered callbacks. Helpers shared with the package'sMedia_Queryport are extracted verbatim withprivaterelaxed toprotected(the content-trio pattern).wp/media-*, tierexperimental,core_since: null(flips when core lands them),proposalpointing at the WordPress/ai PR.wp_handle_sideload,wp_http_validate_url,MEDIA_TRASH, the media capability mapping) exists on the supported floor (WordPress 6.9+).MediaUploadTest/MediaUpdateTest/MediaDeleteTest(tests/Abilities/), ported from the PR's integration tests onto the Registrar-based conventions: negative and positive checks on every permission path (upload_files,edit_post,publishfloors), base64-data and mocked URL transports, trash/force semantics with theMEDIA_TRASHguard, deleted-item field parity against the live media REST endpoint responses, author reassignment, 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
wp_abilities_api_initcallback:( new WordPress\Abilities\Registrar )->register_all();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). A URL payload (array( 'url' => … )) sideloads instead, capped atwp_max_upload_size().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 whileinheritcan be kept.wp_get_ability( 'wp/media-delete' )->execute( array( 'id' => $id ) )trashes (requiresMEDIA_TRASH, elsemedia_trash_not_supported);array( 'id' => $id, 'force' => true )deletes the attachment and its files permanently and returnsdeleted/previous.upload_filesthe upload is denied; update/delete requireedit_post/delete_postfor attachments (a missing item is denied like an unreadable one);private/publishstatuses require the publish capability; deleting another author's attachment requiresdelete_others_posts.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 (trunk + stable, one at a time) pass.Changelog entries
Added (CHANGELOG.md):
wp/media-upload,wp/media-update,wp/media-delete— tierexperimental, faithful ports of the media write abilities from WordPress/ai PR #1104 by @jorgefilipecosta, building on thewp/media-queryfield projection.Co-authored-by: jorgefilipecosta jorgefilipecosta@users.noreply.github.com