Make WordPress Core

Opened 5 days ago

Last modified 5 days ago

#61550 new defect (bug)

Template contents are wiped out on rename

Reported by: alshakero's profile alshakero 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:

  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

Change History (3)

This ticket was mentioned in PR #6955 on WordPress/wordpress-develop by alshakero.


5 days ago
#1

The ticket explains the problem.

Trac ticket: https://core.trac.wordpress.org/ticket/61550

#2 @alshakero
5 days ago

You can see a detailed bug report of this bug with a nice video here.

#3 @hellofromTonya
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.

Note: See TracTickets for help on using tickets.