Skip to content

[in progress] Add a core/content ability#739

Draft
jorgefilipecosta wants to merge 2 commits into
developfrom
add/core-content-ability
Draft

[in progress] Add a core/content ability#739
jorgefilipecosta wants to merge 2 commits into
developfrom
add/core-content-ability

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

Adds the read-only core/content ability to the plugin, mirroring the WordPress core WP_Content_Abilities implementation (see the companion core PR) so the two stay in sync. It overrides any core-provided copy.

Retrieves one or more posts of a post type exposed to abilities: fetch a single post by id or slug, or query multiple posts filtered by post_type, status, author, parent, with a fields selector and page/per_page pagination. Output is { posts, total, total_pages }.

Security

Defense in depth: a coarse status/capability gate plus an authoritative per-post read_post check on every row; default status publish; password-protected content withheld from non-editors; uniform not-found responses to avoid leaking post existence.

Show_In_Abilities

WordPress core does not yet ship the show_in_abilities flag this ability reads, so a self-contained Show_In_Abilities component polyfills it onto curated core post types (post, page). It is structured exactly like the settings polyfill from the core/settings PR (#691), so the two merge cleanly.

This PR is independent of #691 and can be reviewed/merged on its own.

Tests

PHPUnit integration tests for the ability and the polyfill, plus an e2e spec (tests/e2e/specs/abilities/core-content.spec.js) backed by a sample-content plugin that registers an ability-exposed post type.

Open WordPress Playground Preview

Registers the read-only `core/content` ability, which retrieves one or more
posts of a post type exposed to abilities. Fetch a single post by ID or by slug,
or query multiple posts filtered by post type, status, author, or parent, with a
`fields` selector and `page`/`per_page` pagination.

Mirrors the WordPress core `WP_Content_Abilities` implementation so the two stay
in sync, and overrides any core-provided copy. A self-contained Show_In_Abilities
component polyfills the `show_in_abilities` flag onto curated core post types
(post, page) so the ability returns data on a stock site.
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

Mirrors the fixes from the core/settings review (#691) that also apply here:
- Memoize the exposed post types so the input schema and the permission/execute
  callbacks derive from a single walk of the registered post types.
- Default the input schema to an empty object so the type:object default serializes as {}.
- Use __() instead of esc_html__(), and @SInCE x.x.x per CONTRIBUTING.md.
- Harden input/value handling (type guards, capability resolver, non-negative int
  helper) so the new code passes PHPStan at the strictest level.

The `content` ability-category fallback is kept on purpose: unlike `site`, `content`
is a new category not present on the plugin's minimum WordPress (7.0).
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