Add: WordPress Core Post Management Abilities #10665
Open
+1,484
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: