diff --git a/src/wp-includes/blocks/pattern.php b/src/wp-includes/blocks/pattern.php index 870313eb5e86d..508b3221d0522 100644 --- a/src/wp-includes/blocks/pattern.php +++ b/src/wp-includes/blocks/pattern.php @@ -23,6 +23,7 @@ function register_block_core_pattern() { * Renders the `core/pattern` block on the server. * * @since 6.3.0 Backwards compatibility: blocks with no `syncStatus` attribute do not receive block wrapper. + * @since 7.2.0 Processes shortcodes in pattern content. * * @global WP_Embed $wp_embed Used to process embedded content within patterns * @@ -60,6 +61,8 @@ function render_block_core_pattern( $attributes ) { $seen_refs[ $attributes['slug'] ] = true; + $content = shortcode_unautop( $content ); + $content = do_shortcode( $content ); $content = do_blocks( $content ); global $wp_embed; diff --git a/tests/phpunit/tests/blocks/renderBlockCorePattern.php b/tests/phpunit/tests/blocks/renderBlockCorePattern.php new file mode 100644 index 0000000000000..bd69ecf323f4c --- /dev/null +++ b/tests/phpunit/tests/blocks/renderBlockCorePattern.php @@ -0,0 +1,66 @@ +is_registered( self::PATTERN_NAME ) ) { + unregister_block_pattern( self::PATTERN_NAME ); + } + remove_shortcode( self::SHORTCODE_NAME ); + + parent::tear_down(); + } + + /** + * Tests that shortcodes in patterns are processed when rendered in templates. + * + * @ticket 58397 + */ + public function test_renders_shortcode_in_pattern() { + add_shortcode( + self::SHORTCODE_NAME, + static function () { + return 'Shortcode output'; + } + ); + + register_block_pattern( + self::PATTERN_NAME, + array( + 'title' => 'Pattern containing a shortcode', + 'content' => '[pattern_shortcode]', + ) + ); + + $template = ''; + $content = do_shortcode( $template ); + $content = do_blocks( $content ); + + $this->assertSame( "

Shortcode output

\n", $content ); + } +}