From 4cecd0e731682345a380b36bf898e485070a7de2 Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Tue, 23 Jul 2024 13:43:12 +0000 Subject: [PATCH] Block Hooks: Don't erase post content if it isn't changed by client. The `inject_ignored_hooked_blocks_metadata_attributes` filter that is attached to both the `rest_pre_insert_wp_template` and `rest_pre_insert_wp_template_part` hooks receives a `stdClass` object from the Templates REST API controller that contains all fields that the client would like to modify when making a `POST` request (plus the `id` to identify the relevant template or template part, respectively). There are cases when the `post_content` field is not set, e.g. when the client would like to rename an existing template (in which case it would only set the `title` field). Prior to this changeset, the filter would erroneously apply the Block Hooks algorithm to the non-existent `post_content` field regardless, which would result in it being set to the empty string `''`. As a consequence, renaming a template would have the unwanted side effect of wiping its contents. This changeset fixes the issue by returning early from the filter if the `post_content` field is not set. Props alshakero, bernhard-reiter. Fixes #61550. Built from https://develop.svn.wordpress.org/trunk@58785 git-svn-id: http://core.svn.wordpress.org/trunk@58187 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-template-utils.php | 4 ++++ wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index fe43d89564..3c6850bd32 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -1602,6 +1602,10 @@ function inject_ignored_hooked_blocks_metadata_attributes( $changes, $deprecated _deprecated_argument( __FUNCTION__, '6.5.3' ); } + if ( ! isset( $changes->post_content ) ) { + return $changes; + } + $hooked_blocks = get_hooked_blocks(); if ( empty( $hooked_blocks ) && ! has_filter( 'hooked_block_types' ) ) { return $changes; diff --git a/wp-includes/version.php b/wp-includes/version.php index 768d88bed2..2cbeba7ab7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-58784'; +$wp_version = '6.7-alpha-58785'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.