Repository navigation
Editor: Add author support to the wp_block post type - #14269
fabiankaegy wants to merge 4 commits into
Conversation
This exposes each pattern's author through the REST API, so the editor can tell the current user's patterns apart from the rest of the site's patterns.
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 view lists every user-created pattern, not only the current user's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR! Since adding author support changes the behavior of wp_block beyond the REST API, I think we should add some tests:
- REST API: The blocks controller returns
authorin the response, and theauthorandauthor_excludequery parameters filter patterns by author. - REST API: A user without
edit_others_postscan't change the author of a pattern. - Deleting a user: Deleting a user without reassigning their content also deletes their patterns, and reassigning moves them to the new user. This is the same behavior as templates and template parts, but it changes how patterns work today, so a test would document it as intended.
- QUnit fixtures: The REST schema gets new
authorarguments, so the API fixtures probably need to be regenerated.
Covers the author in the blocks controller's response, filtering patterns by author, changing a pattern's author, and what happens to a user's patterns when the user is deleted. Regenerates the REST API client fixtures for the new author arguments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @t-hamano! Added tests for all four:
|
Patterns may be used across the site, so deleting a user shouldn't delete their patterns, now that the post type supports authors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
t-hamano
left a comment
There was a problem hiding this comment.
Regardless of whether WordPress/gutenberg#84680 is merged, I believe it is worth including this PR in 7.2. As mentioned here, this PR exposes the UI to change the author of a block pattern, which I think is a valuable enhancement. cc @peterwilsoncc @Mamaduka
|
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. |
| ), | ||
| array( | ||
| 'title' => __( 'My patterns' ), | ||
| 'title' => __( 'Site patterns' ), |
There was a problem hiding this comment.
I was wondering if we should include it in this PR. It feels unusual when testing because this depends on Gutenberg changes.
I think probably the easiest thing is to keep it in this PR, and if for some reason the gutenberg changes don't make it into 7.2, we can revert this change before 7.2 is shipped.
talldan
left a comment
There was a problem hiding this comment.
This is working well for me. I tested a some different scenarios with different users. Deleting a user that owns patterns worked correctly in my testing, the patterns are kept so continue to render.
The REST API now returns each pattern's author, so the block inserter and the Site Editor's Patterns screen can filter patterns by author. Patterns already store `post_author` and their capabilities already check it. Sets `delete_with_user` to `false`, so deleting a user keeps their patterns, as they may be used across the site. Also renames the Site Editor's "My patterns" view to "Site patterns", since it lists every user-created pattern, not only the current user's. Developed in #14269. Synced from WordPress/gutenberg#84680. Props fabiankaegy, wildworks, talldanwp, jameskoster, mamaduka, fcoveram. Fixes #66307. git-svn-id: https://develop.svn.wordpress.org/trunk@64499 602fd350-edb4-49c9-b593-d223f7449a82
The REST API now returns each pattern's author, so the block inserter and the Site Editor's Patterns screen can filter patterns by author. Patterns already store `post_author` and their capabilities already check it. Sets `delete_with_user` to `false`, so deleting a user keeps their patterns, as they may be used across the site. Also renames the Site Editor's "My patterns" view to "Site patterns", since it lists every user-created pattern, not only the current user's. Developed in WordPress/wordpress-develop#14269. Synced from WordPress/gutenberg#84680. Props fabiankaegy, wildworks, talldanwp, jameskoster, mamaduka, fcoveram. Fixes #66307. Built from https://develop.svn.wordpress.org/trunk@64499 git-svn-id: http://core.svn.wordpress.org/trunk@63649 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Adds
authorsupport to thewp_blockpost type, so the REST API returns each pattern's author. The block inserter and the Site Editor's Patterns screen use it to filter patterns by author.Sets
delete_with_usertofalse, so deleting a user keeps their patterns, as they may be used across the site. Without it, author support would makewp_delete_user()delete them permanently.Also renames the Site Editor's "My patterns" view to "Site patterns", since it lists every user-created pattern, not only the current user's.
The author is already stored on every pattern and the post type's capabilities already check it. This only makes it visible to the editor.
Gutenberg PR: WordPress/gutenberg#84680
Trac ticket: https://core.trac.wordpress.org/ticket/66307
Use of AI Tools
Drafted with Claude Code, reviewed by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.