Changeset 56507 for trunk/src/wp-includes/block-template.php
- Timestamp:
- 09/01/2023 05:30:02 PM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template.php
r56209 r56507 211 211 * @global string $_wp_current_template_content 212 212 * @global WP_Embed $wp_embed 213 * @global WP_Query $wp_query 213 214 * 214 215 * @return string Block template markup. 215 216 */ 216 217 function get_the_block_template_html() { 217 global $_wp_current_template_content; 218 global $wp_embed; 218 global $_wp_current_template_content, $wp_embed, $wp_query; 219 219 220 220 if ( ! $_wp_current_template_content ) { … … 229 229 $content = shortcode_unautop( $content ); 230 230 $content = do_shortcode( $content ); 231 $content = do_blocks( $content ); 231 232 /* 233 * Most block themes omit the `core/query` and `core/post-template` blocks in their singular content templates. 234 * While this technically still works since singular content templates are always for only one post, it results in 235 * the main query loop never being entered which causes bugs in core and the plugin ecosystem. 236 * 237 * The workaround below ensures that the loop is started even for those singular templates. The while loop will by 238 * definition only go through a single iteration, i.e. `do_blocks()` is only called once. Additional safeguard 239 * checks are included to ensure the main query loop has not been tampered with and really only encompasses a 240 * single post. 241 * 242 * Even if the block template contained a `core/query` and `core/post-template` block referencing the main query 243 * loop, it would not cause errors since it would use a cloned instance and go through the same loop of a single 244 * post, within the actual main query loop. 245 */ 246 if ( is_singular() && 1 === $wp_query->post_count && have_posts() ) { 247 while ( have_posts() ) { 248 the_post(); 249 $content = do_blocks( $content ); 250 } 251 } else { 252 $content = do_blocks( $content ); 253 } 254 232 255 $content = wptexturize( $content ); 233 256 $content = convert_smilies( $content );
Note: See TracChangeset
for help on using the changeset viewer.