Try 2: Add get and post/pages abilities.#10867
Try 2: Add get and post/pages abilities.#10867jorgefilipecosta wants to merge 32 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
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. |
| * @return WP_Ability|null The registered ability instance on success, null on failure. | ||
| */ | ||
| public function register( string $name, array $args ): ?WP_Ability { | ||
| if ( ! preg_match( '/^[a-z0-9-]+\/[a-z0-9-]+$/', $name ) ) { |
There was a problem hiding this comment.
This change is extracted in a different PR, and is a temporary just for testing.
d0dfb11 to
0e10ac7
Compare
0e10ac7 to
694b717
Compare
…dation for multiple level nesting
| * - If true, all supported abilities are registered (currently just 'get'). | ||
| * - If false (default), no abilities are registered. | ||
| * - If an array, selectively enable abilities: e.g. array( 'get' => true ). |
There was a problem hiding this comment.
This doesn't seem scalable across other uses of show_in_abilities. I'm also not convinced that we want this sort of inferred granularity from out Object types.
| * support for custom fields for registered meta to be accessible via REST. | ||
| * When registering complex meta values this argument may optionally be an | ||
| * array with 'schema' or 'prepare_callback' keys instead of a boolean. | ||
| * @type bool $show_in_abilities Whether this meta key should be exposed through the Abilities API. |
There was a problem hiding this comment.
https://github.com/WordPress/wordpress-develop/pull/10867/files#r2809753019
Also, what's the logical consumption pattern here, `$show_in_abilities ? register with $show_in_rest['schema'] : don't register at all ?
There was a problem hiding this comment.
Ideally, this would be testing the actual ability. The fact that you can get any exposed ability via a REST endpoint is an implementation detail that's tested elsewhere.
Part of: WordPress/ai#40
Alternative to #10665, trying to implement what was discussed with
@JasonTheAdams and @justlevine.
This PR adds
getabilities for post types via the Abilities API, enabling AI agents to retrieve posts and pages throughcore/post-type/{slug}/get. It Introduce ashow_in_abilitiesoption onregister_post_type()to control which post types expose abilities, enabled by default forpostandpagefor now (if we agree in this approach we will expand to menus, media etc)-Support single-post retrieval by ID and multi-post querying with filters for status, author, search, taxonomy, meta, date, comment status, ping status and more.
I think the biggest decision we need to do is the naming of the ability. I went for
core/post-type/{post-type-slug}/getwhere post-type-slug is the post type identifier (post, page etc). We could discuss other naming possibilities.Test plan
Retrieve a single post by ID with meta and taxonomies (use a valid id):
Query posts filtered by meta key existence:
Nested meta query with AND/OR relations:
Nested taxonomy query with AND/OR relations:
Retrieve most recent pages: