-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add: WordPress Core Post Management Abilities #10665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Add: WordPress Core Post Management Abilities #10665
Conversation
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. |
|
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. |
af66fd3 to
e9aa703
Compare
|
I'm not entirely confident in my thought here, but it is one I've wrestled with so I'll share it here open-handedly. 😄 I go back and forth on the idea of polymorphic abilities like this. That is, should the On the one hand, this is consistent with how the underlying functions work. But do we simply want to surface low-level functions like that to abilities? Are Abilities low level in the same way and are merely another form of function? I'm inclined to say no, my reason being that Abilities are designed to be multi-contextual — direct execution, REST, Command Palette, MCP, AI function declarations, etc. As input and output parameters get more complex, adapting them to these various contexts gets harder. Some contexts handles certain complexity well, while others get tricky fast. Having more specific Abilities also means we can take things like pinning, page templates, attachment sizes, and so forth, and include them as part of the input/output parameters. If we go generic, then we're back to addressing things as meta, which is not as discoverable, not as easy to work with, more fragile, and so forth. Now, one could then wonder about how Abilities work with custom post types, especially those that work very similarly to posts. If there are specific Abilities, then how do those get their own Abilities without folks having to always put in effort to make them? I propose updating
This would use the slug to optionally create Curious what others think! The more I see Abilities used, especially multi-contextually, the more convinced I am that simpler and more focused is better than complexities such as polymorphism. |
|
Thank you a lot for sharing you thoughts @JasonTheAdams. My idea was that both approaches would be complementary we would have a raw building block that supports managing any kind of post. And then specific post types needing more flexibility could register their own abilities which internally may even call or reuse parts of the core one. I think we may also give it a try to the abilities per post type approach (with functionality to automatically generate abilities for a post type) so we can compare both live. The downside I see with that is that we have more abilities, e.g: in a site with 10 simples CPT's using the default management abilities we may easily have 10*4 =40 post management abilities vs just 4 generic ones, which may pollute a little bit the context on LLM agents but if we have good search and filtering abilities that may be acceptable. |
Part of: WordPress/ai#40 cc: @Jameswlepage
Equivalent core PR of: WordPress/gutenberg#74234 (in Gutenberg).
Inspired by the work on https://github.com/galatanovidiu/mcp-adapter-implementation-example/tree/experiment/layerd-mcp-tools/includes/Abilities by @galatanovidiu.
Ticket: https://core.trac.wordpress.org/ticket/64455
Core abilities organization
This PR also proposes a logic for how core abilities are organized. In
abilities.php, we have two functions:wp_register_core_abilitiesandwp_register_ability_category(or in the case of Gutenberg,_gutenberg_register_core_abilitiesand_gutenberg_register_core_ability_categories). These functions then call ability registration functions that are inside the abilities folder. If the ability is simple, it can be registered in just a single internal function, e.g.,_wp_register_site_info_ability; for complex abilities, we can register them in a class (like this post management one).The abilities can be in both Gutenberg and core. Having them in Gutenberg allows us to use them in the workflows functionality that is being worked on by @senadir and allows us to get some testing before core is released.
Gutenberg unregisters the equivalent core ones, so Gutenberg is the source of truth. The same ability can exist in Gutenberg and core, but Gutenberg takes precedence so we can test changes in Gutenberg before releasing in core (similar to what happens with blocks and other WordPress artifacts).
Core Post management abilities
This PR adds core post management abilities for the WordPress abilities API:
core/create-post,core/get-post,core/find-posts, andcore/update-post.It supports nested query support for
meta_query,tax_query, anddate_querymatching WordPress's nativeWP_Querystructure with AND/OR relations. This allows very complex query operations which the REST API does not allow and may be useful for agents to find information.It uses the permission callback mechanism and tries to correctly check permissions for all cases. The basic permission checking logic first checks the basic and common use case (user can edit, create, or see a post), then we go into specifics in separate functions that are reused for checking status changes (e.g., publish), author changes, and taxonomy assignment permissions.
The class
WP_Posts_Abilities_Gutenbergis organized into 6 main areas:wp_register_abilitycalls.WP_Queryformat.Missing
The idea of this PR is mainly to get feedback if this is the right direction for the post management abilities. There are some things that are missing:
wp_corePHP API approach where we have thewp_update_postfunction and alsostick_post/unstick_postfunctions. We can decide on what to do regarding the missing edits as follow-ups, as the PR is already too big.Test plan
/wp-admin/edit.php?post_type=post.core/create-postcreates posts with various fields (title, content, status, meta, taxonomies):core/get-postretrieves posts by ID with optional taxonomy/meta inclusion:core/find-postsqueries work with nestedmeta_query,tax_query, anddate_query.a-23|c-1represents a post with meta key "a" value of 23 and meta key "c" value of 1. Also adds the correct tags.core/update-postmodifies existing posts correctly: