Commit 13521bce0b for wordpress.org

commit 13521bce0b1af07efa1d07667585196347bab883
Author: Bernhard Reiter <Bernhard Reiter@git.wordpress.org>
Date:   Thu Dec 19 13:26:28 2024 +0000

    Block Hooks: Apply to synced patterns.

    Apply Block Hooks to synced patterns (i.e. `core/block` instances).

    Props bernhard-reiter, gziolo.
    Fixes #62704.
    Built from https://develop.svn.wordpress.org/trunk@59543


    git-svn-id: http://core.svn.wordpress.org/trunk@58929 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php
index 6a4ab4636c..25a4a7e3b2 100644
--- a/wp-includes/blocks.php
+++ b/wp-includes/blocks.php
@@ -1219,6 +1219,8 @@ function update_ignored_hooked_blocks_postmeta( $post ) {

 	if ( 'wp_navigation' === $post->post_type ) {
 		$wrapper_block_type = 'core/navigation';
+	} elseif ( 'wp_block' === $post->post_type ) {
+		$wrapper_block_type = 'core/block';
 	} else {
 		$wrapper_block_type = 'core/post-content';
 	}
@@ -1291,7 +1293,7 @@ function insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata( &$parsed_a
  * @return WP_REST_Response The response object.
  */
 function insert_hooked_blocks_into_rest_response( $response, $post ) {
-	if ( empty( $response->data['content']['raw'] ) || empty( $response->data['content']['rendered'] ) ) {
+	if ( empty( $response->data['content']['raw'] ) ) {
 		return $response;
 	}

@@ -1306,6 +1308,8 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {

 	if ( 'wp_navigation' === $post->post_type ) {
 		$wrapper_block_type = 'core/navigation';
+	} elseif ( 'wp_block' === $post->post_type ) {
+		$wrapper_block_type = 'core/block';
 	} else {
 		$wrapper_block_type = 'core/post-content';
 	}
@@ -1327,6 +1331,11 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {

 	$response->data['content']['raw'] = $content;

+	// If the rendered content was previously empty, we leave it like that.
+	if ( empty( $response->data['content']['rendered'] ) ) {
+		return $response;
+	}
+
 	// `apply_block_hooks_to_content` is called above. Ensure it is not called again as a filter.
 	$priority = has_filter( 'the_content', 'apply_block_hooks_to_content' );
 	if ( false !== $priority ) {
diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php
index 18ef8517ed..9eff6ecbeb 100644
--- a/wp-includes/default-filters.php
+++ b/wp-includes/default-filters.php
@@ -760,14 +760,16 @@ add_action( 'init', '_wp_register_default_font_collections' );
 add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' );
 add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' );

-// Update ignoredHookedBlocks postmeta for wp_navigation post type.
+// Update ignoredHookedBlocks postmeta for some post types.
 add_filter( 'rest_pre_insert_page', 'update_ignored_hooked_blocks_postmeta' );
 add_filter( 'rest_pre_insert_post', 'update_ignored_hooked_blocks_postmeta' );
+add_filter( 'rest_pre_insert_wp_block', 'update_ignored_hooked_blocks_postmeta' );
 add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' );

 // Inject hooked blocks into the Posts endpoint REST response for some given post types.
 add_filter( 'rest_prepare_page', 'insert_hooked_blocks_into_rest_response', 10, 2 );
 add_filter( 'rest_prepare_post', 'insert_hooked_blocks_into_rest_response', 10, 2 );
+add_filter( 'rest_prepare_wp_block', 'insert_hooked_blocks_into_rest_response', 10, 2 );
 add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 );

 unset( $filter, $action );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 684edf882a..36a5d14fe6 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '6.8-alpha-59542';
+$wp_version = '6.8-alpha-59543';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.