- Timestamp:
- 10/27/2023 06:16:05 PM (12 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template.php
r56507 r57019 209 209 * @since 5.8.0 210 210 * 211 * @global string $_wp_current_template_id 211 212 * @global string $_wp_current_template_content 212 213 * @global WP_Embed $wp_embed … … 216 217 */ 217 218 function get_the_block_template_html() { 218 global $_wp_current_template_ content, $wp_embed, $wp_query;219 global $_wp_current_template_id, $_wp_current_template_content, $wp_embed, $wp_query; 219 220 220 221 if ( ! $_wp_current_template_content ) { … … 243 244 * loop, it would not cause errors since it would use a cloned instance and go through the same loop of a single 244 245 * post, within the actual main query loop. 246 * 247 * This special logic should be skipped if the current template does not come from the current theme, in which case 248 * it has been injected by a plugin by hijacking the block template loader mechanism. In that case, entirely custom 249 * logic may be applied which is unpredictable and therefore safer to omit this special handling on. 245 250 */ 246 if ( is_singular() && 1 === $wp_query->post_count && have_posts() ) { 251 if ( 252 $_wp_current_template_id && 253 str_starts_with( $_wp_current_template_id, get_stylesheet() . '//' ) && 254 is_singular() && 255 1 === $wp_query->post_count && 256 have_posts() 257 ) { 247 258 while ( have_posts() ) { 248 259 the_post(); -
trunk/tests/phpunit/tests/block-template.php
r57009 r57019 20 20 21 21 public function tear_down() { 22 global $_wp_current_template_ content;23 unset( $_wp_current_template_ content );22 global $_wp_current_template_id, $_wp_current_template_content; 23 unset( $_wp_current_template_id, $_wp_current_template_content ); 24 24 25 25 parent::tear_down(); … … 194 194 * 195 195 * @ticket 58154 196 * @ticket 59736 196 197 * @covers ::get_the_block_template_html 197 198 */ 198 199 public function test_get_the_block_template_html_enforces_singular_query_loop() { 199 global $_wp_current_template_ content, $wp_query, $wp_the_query;200 global $_wp_current_template_id, $_wp_current_template_content, $wp_query, $wp_the_query; 200 201 201 202 // Register test block to log `in_the_loop()` results. … … 208 209 $wp_the_query = $wp_query; 209 210 211 // Force a template ID that is for the current stylesheet. 212 $_wp_current_template_id = get_stylesheet() . '//single'; 210 213 // Use block template that just renders post title and the above test block. 211 214 $_wp_current_template_content = '<!-- wp:post-title /--><!-- wp:test/in-the-loop-logger /-->'; … … 228 231 */ 229 232 public function test_get_the_block_template_html_does_not_generally_enforce_loop() { 230 global $_wp_current_template_ content, $wp_query, $wp_the_query;233 global $_wp_current_template_id, $_wp_current_template_content, $wp_query, $wp_the_query; 231 234 232 235 // Register test block to log `in_the_loop()` results. … … 248 251 ); 249 252 $wp_the_query = $wp_query; 253 254 // Force a template ID that is for the current stylesheet. 255 $_wp_current_template_id = get_stylesheet() . '//home'; 250 256 251 257 /* … … 278 284 279 285 /** 286 * Tests that `get_the_block_template_html()` does not start the main query loop when on a template that is not from the current theme. 287 * 288 * @ticket 58154 289 * @ticket 59736 290 * @covers ::get_the_block_template_html 291 */ 292 public function test_get_the_block_template_html_skips_singular_query_loop_when_non_theme_template() { 293 global $_wp_current_template_id, $_wp_current_template_content, $wp_query, $wp_the_query; 294 295 // Register test block to log `in_the_loop()` results. 296 $in_the_loop_logs = array(); 297 $this->register_in_the_loop_logger_block( $in_the_loop_logs ); 298 299 // Set main query to single post. 300 $post_id = self::factory()->post->create( array( 'post_title' => 'A single post' ) ); 301 $wp_query = new WP_Query( array( 'p' => $post_id ) ); 302 $wp_the_query = $wp_query; 303 304 // Force a template ID that is not for the current stylesheet. 305 $_wp_current_template_id = 'some-plugin-slug//single'; 306 // Use block template that just renders post title and the above test block. 307 $_wp_current_template_content = '<!-- wp:post-title /--><!-- wp:test/in-the-loop-logger /-->'; 308 309 $output = get_the_block_template_html(); 310 $this->unregister_in_the_loop_logger_block(); 311 $this->assertSame( array( false ), $in_the_loop_logs, 'Main query loop was triggered despite a custom block template outside the current theme being used' ); 312 } 313 314 /** 280 315 * @ticket 58319 281 316 * -
trunk/tests/phpunit/tests/media.php
r56694 r57019 80 80 */ 81 81 public function tear_down() { 82 global $_wp_current_template_id, $_wp_current_template_content; 83 unset( $_wp_current_template_id, $_wp_current_template_content ); 84 82 85 parent::tear_down(); 83 86 … … 3973 3976 */ 3974 3977 public function test_wp_filter_content_tags_does_not_lazy_load_first_image_in_block_theme() { 3975 global $_wp_current_template_ content, $wp_query, $wp_the_query, $post;3978 global $_wp_current_template_id, $_wp_current_template_content, $wp_query, $wp_the_query, $post; 3976 3979 3977 3980 // Do not add srcset, sizes, or decoding attributes as they are irrelevant for this test. … … 4002 4005 $post = get_post( self::$post_ids['publish'] ); 4003 4006 4007 // Force a template ID that is for the current stylesheet. 4008 $_wp_current_template_id = get_stylesheet() . '//single'; 4004 4009 $_wp_current_template_content = '<!-- wp:post-content /-->'; 4005 4010 … … 4021 4026 */ 4022 4027 public function test_wp_filter_content_tags_does_not_lazy_load_first_featured_image_in_block_theme() { 4023 global $_wp_current_template_ content, $wp_query, $wp_the_query, $post;4028 global $_wp_current_template_id, $_wp_current_template_content, $wp_query, $wp_the_query, $post; 4024 4029 4025 4030 // Do not add srcset, sizes, or decoding attributes as they are irrelevant for this test. … … 4070 4075 $post = get_post( self::$post_ids['publish'] ); 4071 4076 4077 // Force a template ID that is for the current stylesheet. 4078 $_wp_current_template_id = get_stylesheet() . '//single'; 4072 4079 $_wp_current_template_content = '<!-- wp:post-featured-image /--> <!-- wp:post-content /-->'; 4073 4080 … … 4088 4095 */ 4089 4096 public function test_wp_filter_content_tags_does_not_lazy_load_images_in_header() { 4090 global $_wp_current_template_ content;4097 global $_wp_current_template_id, $_wp_current_template_content; 4091 4098 4092 4099 // Do not add srcset, sizes, or decoding attributes as they are irrelevant for this test. … … 4123 4130 wp_set_post_terms( $footer_post_id, get_stylesheet(), 'wp_theme' ); 4124 4131 4132 // Force a template ID that is for the current stylesheet. 4133 $_wp_current_template_id = get_stylesheet() . '//single'; 4125 4134 $_wp_current_template_content = '<!-- wp:template-part {"slug":"header","theme":"' . get_stylesheet() . '","tagName":"header"} /--><!-- wp:template-part {"slug":"footer","theme":"' . get_stylesheet() . '","tagName":"footer"} /-->'; 4126 4135
Note: See TracChangeset
for help on using the changeset viewer.