diff --git a/src/wp-includes/block-template.php b/src/wp-includes/block-template.php index 0a4d85ac718a9..dc0a7c34798d1 100644 --- a/src/wp-includes/block-template.php +++ b/src/wp-includes/block-template.php @@ -207,16 +207,14 @@ function _block_template_render_title_tag() { * * @access private * @since 5.8.0 + * @since 6.6.0 Block template content now runs through a 'the_block_template_html' filter. * - * @global string $_wp_current_template_id - * @global string $_wp_current_template_content - * @global WP_Embed $wp_embed WordPress Embed object. - * @global WP_Query $wp_query WordPress Query object. + * @global string $_wp_current_template_content * * @return string Block template markup. */ function get_the_block_template_html() { - global $_wp_current_template_id, $_wp_current_template_content, $wp_embed, $wp_query; + global $_wp_current_template_content; if ( ! $_wp_current_template_content ) { if ( is_user_logged_in() ) { @@ -225,10 +223,36 @@ function get_the_block_template_html() { return; } - $content = $wp_embed->run_shortcode( $_wp_current_template_content ); - $content = $wp_embed->autoembed( $content ); - $content = shortcode_unautop( $content ); - $content = do_shortcode( $content ); + $content = $_wp_current_template_content; + + /** + * Filters the block template content. + * + * @since 6.6.0 + * + * @param string $content The entire block template content. + */ + $content = apply_filters( 'the_block_template_html', $content ); + $content = str_replace( ']]>', ']]>', $content ); + + // Wrap block template in .wp-site-blocks to allow for specific descendant styles + // (e.g. `.wp-site-blocks > *`). + return '
' . $content . '
'; +} + +/** + * Parses dynamic blocks from the block template and re-renders them. + * + * @since 6.6.0 + * + * @global WP_Query $wp_query + * @global string $_wp_current_template_id + * + * @param string $content Block template content. + * @return string Updated block template content. + */ +function do_block_template_blocks( $content ) { + global $wp_query, $_wp_current_template_id; /* * Most block themes omit the `core/query` and `core/post-template` blocks in their singular content templates. @@ -257,20 +281,13 @@ function get_the_block_template_html() { ) { while ( have_posts() ) { the_post(); + $content = do_blocks( $content ); } - } else { - $content = do_blocks( $content ); + return $content; } - $content = wptexturize( $content ); - $content = convert_smilies( $content ); - $content = wp_filter_content_tags( $content, 'template' ); - $content = str_replace( ']]>', ']]>', $content ); - - // Wrap block template in .wp-site-blocks to allow for specific descendant styles - // (e.g. `.wp-site-blocks > *`). - return '
' . $content . '
'; + return do_blocks( $content ); } /** diff --git a/src/wp-includes/class-wp-embed.php b/src/wp-includes/class-wp-embed.php index 6b9eaa25db7bc..58102f2dfe1b9 100644 --- a/src/wp-includes/class-wp-embed.php +++ b/src/wp-includes/class-wp-embed.php @@ -30,6 +30,7 @@ class WP_Embed { */ public function __construct() { // Hack to get the [embed] shortcode to run before wpautop(). + add_filter( 'the_block_template_html', array( $this, 'run_shortcode' ), 6 ); add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 ); add_filter( 'widget_text_content', array( $this, 'run_shortcode' ), 8 ); add_filter( 'widget_block_content', array( $this, 'run_shortcode' ), 8 ); @@ -38,6 +39,7 @@ public function __construct() { add_shortcode( 'embed', '__return_false' ); // Attempts to embed all URLs in a post. + add_filter( 'the_block_template_html', array( $this, 'autoembed' ), 6 ); add_filter( 'the_content', array( $this, 'autoembed' ), 8 ); add_filter( 'widget_text_content', array( $this, 'autoembed' ), 8 ); add_filter( 'widget_block_content', array( $this, 'autoembed' ), 8 ); diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 1bcd85e79aaf5..073c5f42f2a21 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -603,6 +603,14 @@ // Global styles custom CSS. add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles_custom_css' ); +// Block template. +add_filter( 'the_block_template_html', 'shortcode_unautop', 7 ); +add_filter( 'the_block_template_html', 'do_shortcode', 8 ); +add_filter( 'the_block_template_html', 'do_block_template_blocks', 9 ); +add_filter( 'the_block_template_html', 'wptexturize' ); +add_filter( 'the_block_template_html', 'wp_filter_content_tags' ); +add_filter( 'the_block_template_html', 'convert_smilies', 20 ); + // Block supports, and other styles parsed and stored in the Style Engine. add_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' ); add_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 ); diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index c960e44c460f9..38a4c9f2cbe7e 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -1843,6 +1843,11 @@ function wp_lazy_loading_enabled( $tag_name, $context ) { function wp_filter_content_tags( $content, $context = null ) { if ( null === $context ) { $context = current_filter(); + + // For backward compatibility, continue using the 'template' context for the block template. + if ( 'the_block_template_html' === $context ) { + $context = 'template'; + } } $add_iframe_loading_attr = wp_lazy_loading_enabled( 'iframe', $context );