Repository navigation
Conversation
Introduce `WP_Abilities_Media` in `wp-includes/abilities/class-wp-abilities-media.php` and register it from `wp_register_core_abilities()` to expose four abilities in the `content` category: - `core/media-query`: Read-only paginated attachment query with `ids`, `slugs`, `status`, `media_type`, `mime_type`, `post`, and `author` filters, field projection, and row-level permission/visibility checks. - `core/media-upload`: Creates an attachment from an image URL or base64 payload with filename and optional metadata, enforcing `upload_files` and parent `edit_post` permissions. - `core/media-update`: Updates attachment metadata, date, author, or parent post (`0` to detach), enforcing `edit_post` and `media_cannot_attach` checks. - `core/media-delete`: Trashes or permanently deletes an attachment, returning `media_trash_not_supported` (501) when `MEDIA_TRASH` is disabled and `permanent` is not set. Adds unit tests in `tests/phpunit/tests/abilities-api/wpRegisterCoreMediaAbilities.php`. Props therssoftware. Fixes #66719.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: 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:
|
This comment has been minimized.
This comment has been minimized.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…n `WP_Abilities_Media`. Resolves PHPStan `wordpress.hookDocMissing` notice on PR WordPress#16079. Props therssoftware. See #66719.
|
Hi @robelsust, I had a PR in progress on AI plugin for this abilities WordPress/ai#1104, which I'm porting at #16138. #16138 covers more permission cases, and has a wider test coverage I guess we can keep iteration on it. Would appreciate any feedback you may have there. |
Trac ticket: https://core.trac.wordpress.org/ticket/66719
What?
Adds the four core media abilities (
core/media-query,core/media-upload,core/media-update, andcore/media-delete) in a newWP_Abilities_Mediaclass registered viawp_register_core_abilities().Why?
Exposes standard media library read, upload, update, and delete operations through the Abilities API in the
contentcategory, matching the input/output schemas and error semantics defined inCORE-SHAPE.md(WordPress/abilities#22).How?
src/wp-includes/abilities/class-wp-abilities-media.php:core/media-query: Read-only paginated attachment query supportingwhere(ids,slugs,status,media_type,mime_type,post,author),fieldsprojection,pagination,rawfield gating (edit_post), author visibility checks, andmedia_cannot_filter_by_status(403).core/media-upload: Requiresupload_files; supports image URL sideloading (rejecting non-image URLs withmedia_invalid_file400) and base64 + filename uploads; validates parentedit_post(media_cannot_attach403) and author assignment (edit_others_posts).core/media-update: Requiresedit_post(media_not_found404 /media_cannot_edit403); updatestitle,caption,description,alt_text,slug,date,author, andpost(0to detach).core/media-delete: Requiresdelete_post(media_not_found404 /media_cannot_delete403); returnsmedia_trash_not_supported(501) whenMEDIA_TRASHis off andpermanentis not set; trashes or permanently deletes attachments.src/wp-includes/abilities.phpto requireclass-wp-abilities-media.phpand call( new WP_Abilities_Media() )->register().tests/phpunit/tests/abilities-api/wpRegisterCoreMediaAbilities.php.Testing Instructions
./vendor/bin/phpunit --group abilities-api(928 tests, 3221 assertions — passed)../vendor/bin/phpcs src/wp-includes/abilities.php src/wp-includes/abilities/class-wp-abilities-media.php tests/phpunit/tests/abilities-api/wpRegisterCoreMediaAbilities.php(passed).AI Usage Details
WP_Abilities_MediaagainstCORE-SHAPE.md, wire it intowp_register_core_abilities(), write the PHPUnit test suite inwpRegisterCoreMediaAbilities.php, and run PHPUnit and PHPCS. All code and test results were reviewed before committing.