Skip to content

Add a core/media-query ability (read-only Media Library coverage) #1062

Description

@whyisjake

Split out from #40, as requested there on 2026-07-16, so the media abilities can be planned and tracked on their own.

What problem does this address?

The WordPress 7.2 roadmap commits the AI team to "expand read-only coverage to resources such as media, taxonomies, and comments." Today the core/read-* set covers settings, content (posts and pages), and users; nothing lets an agent or an MCP client discover what is in the Media Library, so the most common editorial asks ("find the hero image we used for the spring campaign", "which attachments have no alt text") cannot be answered through abilities.

Proposal

Add a single read ability following the read/manage pattern from the merge proposal and the shape core/read-content already established:

  • Name: core/media-query
  • Category: content
  • Input: id (single attachment) or list arguments: search, mime_type (family or exact), parent (attached post), author, date_query (deferred, as for content), per_page, page, orderby, order. Returns total and total_pages alongside items so callers can page.
  • Output per item: id, title, alt text, caption, description, mime type, file size, dimensions where applicable, source URL, available sizes (name, URL, dimensions), parent post id, author id, dates, and meta limited to registered, show_in_rest meta. No file contents.
  • Permission: mirrors the REST wp/v2/media read checks: upload_files for listing, per-item read_post on the attachment, unattached items visible only to users who can upload_files. Private parents hide their attachments unless the caller can read the parent.
  • Annotations: readonly: true, idempotent: true, destructive: false.
  • Exposure: public => false by default like the other core reads; show_in_rest opt-in.

Out of scope here: uploading, editing, or deleting attachments (core/manage-media, tracked separately), and image generation.

Why this shape

Acceptance

  • Unit tests for: listing with each filter, single item by id, pagination totals, unattached items hidden from a contributor, attachment of a private post hidden from a subscriber, show_in_rest meta only.
  • Abilities Explorer shows and can execute it.
  • Exposed through the MCP Adapter as a tool with correct annotations.
  • Added to the WordPress Core Abilities #40 checklist and to docs/abilities.md (or wherever the core reads are documented).

Path to core

Prototype here per the 7.1 deferral decision; open the Trac ticket once the shape has settled, alongside core/content-query (#64606) and core/users-query (#64657).

Activity

  1. sarthaknagoshe2002 commented on Sep 28, 2026

    @sarthaknagoshe2002

    I would love to take this on!

    The proposal makes complete sense. I will start scaffolding core/read-media wiring the input arguments directly into the existing REST media controller logic to ensure the permission model (upload_files for listing, read_post for attachments) remains identical.

  2. added this to the Future Release milestone on Sep 29, 2026
  3. jeffpaul commented on Sep 29, 2026

    @jeffpaul
    Member

    @sarthaknagoshe2002 you'll likely want to verify approach with @jorgefilipecosta first to ensure what's planned aligns with his decided approach for abilities broadly-speaking

  4. sarthaknagoshe2002 commented on Sep 29, 2026

    @sarthaknagoshe2002

    Hi @jeffpaul and @jorgefilipecosta,

    Thanks for the ping! I have the implementation and test suite ready locally. To make sure it aligns with Jorge's approach across the core abilities suite (mirroring the patterns established in core/read-content #739 and core/read-users), here is a summary of the approach taken:

    1. Shape & Schema

    • Name & Category: core/read-media registered in the content category (gated under the Custom Abilities experiment with wp_abilities_api_init priority 11 to cleanly override core copies).
    • Dual Mode (oneOf):
      • Single Item Mode (id): Returns the media object directly.
      • Collection Query Mode (search, mime_type, parent, author, per_page, page, orderby, order): Returns { items, total, total_pages }.
    • Validation: Strict additionalProperties: false on each branch with branch-local defaults omitted from schema (handled via runtime fallbacks) for clean client-side validator compilation.

    2. Permissions (Parity with REST wp/v2/media)

    • Query Mode: Coarse check requiring the upload_files capability (subscribers and contributors cannot list the media library).
    • Single Item & Row-level:
      • Attached items: Checks read_post on the parent post (attachments of private posts are hidden unless the caller has read access to the parent).
      • Unattached or Orphaned items: Requires both upload_files and read_post on the attachment (hides unattached private media from non-owner authors).

    3. Output & Efficiency

    • Output fields: id, title, alt_text, caption, description, mime_type, file_size, dimensions (width, height), source_url, available_sizes, parent, author, date, date_gmt, modified, modified_gmt, and meta.
    • Safe strings: Returns raw strings for caption and description to prevent the_content / wpautop / autoembed filters from injecting HTML wrappers (like <p class="attachment">).
    • available_sizes: Structured array of image sub-sizes (thumbnail, medium, full, etc.) for images; empty array for non-image attachments.
    • Meta: Restricts meta strictly to registered post meta with show_in_rest => true.
    • Annotations: readonly: true, idempotent: true, destructive: false, open_world: false.

    4. Tests & Quality

    • Integration Tests: PHPUnit test suite covering role-based permissions (Admin, Author, Contributor, Subscriber, Anonymous, non-owner Author), orphaned parents, unattached private media, exact pagination, registered show_in_rest meta, and core override behavior.
    • E2E Tests: Playwright spec testing client-side executeAbility( 'core/read-media', ... ) from @wordpress/abilities in the browser.

    @jorgefilipecosta, please let me know if this approach sounds good or if there are any specific adjustments you'd like made. If everything looks good, I can push the branch and open the PR right away!

  5. changed the title [-]Add a core/read-media ability (read-only Media Library coverage)[/-] [+]Add a `core/media-query` ability (read-only Media Library coverage)[/+] on Oct 1, 2026
  6. gziolo commented on Oct 1, 2026

    @gziolo
    Member

    I’ve updated the title and description to reflect yesterday’s Core AI chat and the direction @jorgefilipecosta shared in the draft proposal. We’re aligning the names of read-only abilities that query collections around core/$collection-query, so this ability becomes core/media-query.

  7. moved this from To do to In progress in WordPress AI Roadmapon Oct 1, 2026
  8. modified the milestones: Future Release, 1.5.0 on Oct 4, 2026
  9. jeffpaul commented on Oct 4, 2026

    @jeffpaul
    Member

    For those following along here, please give a review of #1098 to help keep things moving along, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions