[wp-trac] [WordPress Trac] #61550: Template contents are wiped out on rename
WordPress Trac
noreply at wordpress.org
Tue Jul 2 17:34:49 UTC 2024
#61550: Template contents are wiped out on rename
--------------------------+-----------------------------
Reporter: alshakero | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: trunk
Severity: minor | Keywords: has-patch
Focuses: |
--------------------------+-----------------------------
If you have a custom filter hooked to the `hooked_block_types`, renaming a
`wp_template` will wipe its contents.
This stems from the callback
`inject_ignored_hooked_blocks_metadata_attributes` checking `has_filter(
'hooked_block_types' )` and filtering the template content when this call
returns true. You can see the code
[https://github.com/WordPress/WordPress/blob/b048f2a05482d8dc5b9564a8404b1ca7dd8b515c
/wp-includes/block-template-utils.php#L1606 here].
This is fine, but it assumes that the changes request will always have the
post content, which is not true in the case of renaming. This assumption
results in
[https://github.com/WordPress/WordPress/blob/b048f2a05482d8dc5b9564a8404b1ca7dd8b515c
/wp-includes/block-template-utils.php#L1682 this code] running, even when
there are no changes to the post content, which sets the `post_content` to
an empty string, overwriting the original content.
**To reproduce:**
1. Add an `mu-plugin` containing the following code: `function somehook()
{}; add_filter( 'hooked_block_types', 'somehook' , 10, 4 );`.
2. Rename a custom template.
3. Its content will be wiped out.
**Patch**: https://github.com/WordPress/WordPress/pull/710
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61550>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list