diff --git a/backport-changelog/6.6/6559.md b/backport-changelog/6.6/6559.md new file mode 100644 index 00000000000000..176a2e04f02574 --- /dev/null +++ b/backport-changelog/6.6/6559.md @@ -0,0 +1,6 @@ +https://github.com/WordPress/wordpress-develop/pull/6559 + +* https://github.com/WordPress/gutenberg/pull/60349 +* https://github.com/WordPress/gutenberg/pull/60464 +* https://github.com/WordPress/gutenberg/pull/60491 +* https://github.com/WordPress/gutenberg/pull/61757 diff --git a/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php b/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php index 0e16250acc89a2..e670afacea5b33 100644 --- a/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php +++ b/lib/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php @@ -118,4 +118,14 @@ public function get_template_fallback( $request ) { return rest_ensure_response( $response ); } + + /** + * See WP_REST_Templates_Controller::prepare_item_for_response + */ + public function prepare_item_for_response( $item, $request ) { + $blocks = parse_blocks( $item->content ); + $blocks = gutenberg_replace_pattern_blocks( $blocks ); + $item->content = serialize_blocks( $blocks ); + return parent::prepare_item_for_response( $item, $request ); + } } diff --git a/lib/compat/wordpress-6.6/resolve-patterns.php b/lib/compat/wordpress-6.6/resolve-patterns.php index dafda83266768e..5105619c42613c 100644 --- a/lib/compat/wordpress-6.6/resolve-patterns.php +++ b/lib/compat/wordpress-6.6/resolve-patterns.php @@ -61,25 +61,6 @@ function gutenberg_replace_pattern_blocks( $blocks, &$inner_content = null ) { return $blocks; } -function gutenberg_replace_pattern_blocks_get_block_templates( $templates ) { - foreach ( $templates as $template ) { - $blocks = parse_blocks( $template->content ); - $blocks = gutenberg_replace_pattern_blocks( $blocks ); - $template->content = serialize_blocks( $blocks ); - } - return $templates; -} - -function gutenberg_replace_pattern_blocks_get_block_template( $template ) { - if ( null === $template ) { - return $template; - } - $blocks = parse_blocks( $template->content ); - $blocks = gutenberg_replace_pattern_blocks( $blocks ); - $template->content = serialize_blocks( $blocks ); - return $template; -} - function gutenberg_replace_pattern_blocks_patterns_endpoint( $result, $server, $request ) { if ( $request->get_route() !== '/wp/v2/block-patterns/patterns' ) { return $result; @@ -98,10 +79,6 @@ function gutenberg_replace_pattern_blocks_patterns_endpoint( $result, $server, $ return $result; } -// For core merge, we should avoid the double parse and replace the patterns in templates here: -// https://github.com/WordPress/wordpress-develop/blob/02fb53498f1ce7e63d807b9bafc47a7dba19d169/src/wp-includes/block-template-utils.php#L558 -add_filter( 'get_block_templates', 'gutenberg_replace_pattern_blocks_get_block_templates' ); -add_filter( 'get_block_template', 'gutenberg_replace_pattern_blocks_get_block_template' ); // Similarly, for patterns, we can avoid the double parse here: // https://github.com/WordPress/wordpress-develop/blob/02fb53498f1ce7e63d807b9bafc47a7dba19d169/src/wp-includes/class-wp-block-patterns-registry.php#L175 add_filter( 'rest_post_dispatch', 'gutenberg_replace_pattern_blocks_patterns_endpoint', 10, 3 );