Opened 5 days ago
Last modified 5 days ago
#61550 new defect (bug)
Template contents are wiped out on rename
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | minor | Version: | trunk |
Component: | Editor | Keywords: | has-patch |
Focuses: | Cc: |
Description
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 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 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:
- Add an
mu-plugin
containing the following code:function somehook() {}; add_filter( 'hooked_block_types', 'somehook' , 10, 4 );
. - Rename a custom template.
- Its content will be wiped out.
Change History (3)
This ticket was mentioned in PR #6955 on WordPress/wordpress-develop by alshakero.
5 days ago
#1
#3
@
5 days ago
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 here.
This ticket identifies [58614] / #60854 as the possible change introducing the issue. Pinging @bernhard-reiter for awareness.
The ticket explains the problem.
Trac ticket: https://core.trac.wordpress.org/ticket/61550