Make WordPress Core


Ignore:
Timestamp:
10/27/2023 06:34:11 PM (7 months ago)
Author:
flixos90
Message:

Themes: Skip wrapping block template for singular content with a main query loop when the template was injected from outside the current theme.

As a follow up to [56507], this fixes a bug that could occur for instance when plugins hijack the block template detection process to inject their own block template with entirely custom logic.

Props afragen, hellofromTonya, costdev, mukesh27, huzaifaalmesbah, flixos90.
Merges [57019] to the 6.4 branch.
Fixes #59736.
See #58154.

Location:
branches/6.4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.4

  • branches/6.4/tests/phpunit/tests/media.php

    r56694 r57020  
    8080     */
    8181    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
    8285        parent::tear_down();
    8386
     
    39733976     */
    39743977    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;
    39763979
    39773980        // Do not add srcset, sizes, or decoding attributes as they are irrelevant for this test.
     
    40024005        $post         = get_post( self::$post_ids['publish'] );
    40034006
     4007        // Force a template ID that is for the current stylesheet.
     4008        $_wp_current_template_id      = get_stylesheet() . '//single';
    40044009        $_wp_current_template_content = '<!-- wp:post-content /-->';
    40054010
     
    40214026     */
    40224027    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;
    40244029
    40254030        // Do not add srcset, sizes, or decoding attributes as they are irrelevant for this test.
     
    40704075        $post         = get_post( self::$post_ids['publish'] );
    40714076
     4077        // Force a template ID that is for the current stylesheet.
     4078        $_wp_current_template_id      = get_stylesheet() . '//single';
    40724079        $_wp_current_template_content = '<!-- wp:post-featured-image /--> <!-- wp:post-content /-->';
    40734080
     
    40884095     */
    40894096    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;
    40914098
    40924099        // Do not add srcset, sizes, or decoding attributes as they are irrelevant for this test.
     
    41234130        wp_set_post_terms( $footer_post_id, get_stylesheet(), 'wp_theme' );
    41244131
     4132        // Force a template ID that is for the current stylesheet.
     4133        $_wp_current_template_id      = get_stylesheet() . '//single';
    41254134        $_wp_current_template_content = '<!-- wp:template-part {"slug":"header","theme":"' . get_stylesheet() . '","tagName":"header"} /--><!-- wp:template-part {"slug":"footer","theme":"' . get_stylesheet() . '","tagName":"footer"} /-->';
    41264135
Note: See TracChangeset for help on using the changeset viewer.