#66307 closed enhancement (fixed)
Editor: Add author support to the wp_block post type
| Reported by: | fabiankaegy | Owned by: | fabiankaegy |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch gutenberg-merge has-unit-tests |
| Cc: | Focuses: |
Description
The wp_block post type doesn't register author support, so the REST API doesn't return a pattern's author. Patterns already store post_author, and the post type's capabilities already check it, so this only makes it visible to the editor.
The block inserter uses it to split the "My patterns" category into "Site patterns" (every pattern on the site) and "My patterns" (only the ones the current user created).
Gutenberg PR: https://github.com/WordPress/gutenberg/pull/84680
Core PR: https://github.com/WordPress/wordpress-develop/pull/14269
Change History (9)
This ticket was mentioned in PR #14269 on WordPress/wordpress-develop by @fabiankaegy.
3 weeks ago
#1
@fabiankaegy commented on PR #14269:
3 weeks ago
#2
Thanks @t-hamano! Added tests for all four:
- The blocks controller returns
author, andauthor/author_excludefilter patterns by author. - An author can't change a pattern's author (403), an editor can.
- Deleting a user without reassigning deletes their patterns, and reassigning moves them. Worth noting: only posts and pages go to the trash, so the patterns are deleted permanently. Happy to set
delete_with_usertofalseinstead if we'd rather keep today's behavior. - Regenerated the QUnit fixtures.
#4
@
3 weeks ago
While comparing the view config endpoint in wordpress-develop with gutenberg's, I've noticed some changes related to this ticket where missing. I've prepared https://github.com/WordPress/wordpress-develop/pull/14495 to address that and also extract a new util from existing code that we'll be using in subsequent pull requests.
This ticket was mentioned in PR #14501 on WordPress/wordpress-develop by @ravipatel.
3 weeks ago
#5
- Keywords has-unit-tests added
[64499] stopped patterns (wp_block) from being deleted with their author by setting delete_with_user to false. wp_delete_user() respects that, but on multisite wpmu_delete_user() deletes every post the user wrote, of any post type, so deleting a user from the network still deletes their patterns. They're deleted permanently, since only posts and pages go to the trash.
This makes wpmu_delete_user() skip post types registered with 'delete_with_user' => false. All other posts are deleted as before, including post types with delete_with_user left as null, so nothing else changes on multisite. The same fix also keeps templates, template parts, global styles and navigation menus, which are also registered with delete_with_user set to false.
Testing
Run the new multisite tests:
npm run test:php -- -c tests/phpunit/multisite.xml --filter wpmu_delete_user tests/phpunit/tests/user/multisite.php
- All 6 pass with the fix. Without it, the 3 "should be kept" cases fail.
- The multisite
user,ms-userandms-sitegroups pass (1,881 tests, no failures).
Manual test:
- On multisite, create an Author on a site and create a pattern as that user.
- In Network Admin › Users, delete the user and choose to delete their content.
- Before: the pattern is gone. After: the pattern is kept.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the multisite case, writing the fix and the tests, and running the checks. I reviewed the code and the results.
#6
@
3 weeks ago
On multisite, patterns are still deleted with their author.
[64499] sets delete_with_user to false for wp_block, which wp_delete_user() respects. But deleting a user from the network goes through wpmu_delete_user(), which deletes every post the user wrote, of any post type, without checking delete_with_user. Because wp_block is not post or page, wp_delete_post() deletes the pattern permanently instead of moving it to the trash.
Steps to reproduce:
- On a multisite install, create a user with the Author role on a site and create a pattern as that user.
- In Network Admin › Users, delete the user and choose to delete their content, not attribute it to another user.
- The pattern is gone and isn't in the trash, so content using it as a synced pattern loses it.
The same applies to the other core post types with delete_with_user set to false, such as templates, template parts, global styles and navigation menus.
wpmu_delete_user()'s docblock says it deletes "all posts (of all post types)", so this may have been intentional before. I think the intent of this ticket, keeping patterns used across the site, should hold on multisite too.
PR: https://github.com/WordPress/wordpress-develop/pull/14501
wpmu_delete_user()skips post types registered with'delete_with_user' => false. Everything else is deleted as before, including post types withdelete_with_userleft asnull, so nothing else changes on multisite.- Adds multisite tests for patterns, for a pattern on a second site, and for a custom post type with each
delete_with_uservalue. The pattern tests fail without the fix.
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the multisite case, writing the fix and the tests, and running the checks. I reviewed the code and the results.
This ticket was mentioned in Slack in #core-multisite by ravi. View the logs.
2 weeks ago
@johnjamesjacoby commented on PR #14501:
2 weeks ago
#8
Thanks for working on this. Preserving patterns that may still be used across a site makes sense. I had a few questions after tracing the multisite deletion path:
- When a site has another eligible user, the Network Admin form submits a
blog[https://github.com/WordPress/wordpress-develop/blob/d3a0492e842a7fe8533ca83f3c59408d2bfc2171/src/wp-admin/network/users.php#L218-L241 ...]value, and [the handler callsremove_user_from_blog()beforewpmu_delete_user()]. Removing the user clears the capability metadata thatget_blogs_of_user()uses, sowpmu_delete_user()may find no sites and skip this new query. On “Delete all content,” ordinary posts may remain published as well. This call order predates the PR, but it seems to affect the manual scenario described here. Could we cover that Network Admin flow in a test and confirm that ordinary posts are deleted while patterns are kept?
- `$post_types_to_keep` is gathered before switching sites. A post type registered only by a plugin active on another site may not be available in this request, even if it sets
delete_with_usertofalse. That makes a general promise about plugin post types difficult to keep. A first step scoped to Core post types, with the site-specific plugin case noted for follow-up, might be reasonable here. What do you think?
- A retained pattern will still have the deleted user's ID in
post_author. Single-site deletion already permits this for retained post types, so I don't think it needs to block this fix by itself. Could we make that behavior explicit in a test or note? The author may display as “(no author)” after the account is removed.
Thanks again for tackling the underlying content-loss problem.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Adds
authorsupport to thewp_blockpost type, so the REST API returns each pattern's author. The block inserter uses it to split the "My patterns" category into "Site patterns" (every pattern on the site) and "My patterns" (only the ones the current user created).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: https://github.com/WordPress/gutenberg/pull/84680
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.