Make WordPress Core

Changeset 57009 for trunk


Ignore:
Timestamp:
10/26/2023 06:42:46 PM (9 months ago)
Author:
flixos90
Message:

Themes: Fix block theme supports being added too early, leading to Customizer live preview bugs in 6.4.

The Customizer live preview broke because of [56635], however the root cause for the bug was a lower-level problem that had been present since WordPress 5.8: The block theme specific functions _add_default_theme_supports() and wp_enable_block_templates() were being hooked into the setup_theme action, which fires too early to initialize theme features. Because of that, theme functionality would be initialized before the current theme setup being completed. In the case of the Customizer, that includes overriding which theme is the current theme entirely, thus leading to an inconsistent experience.

This changeset fixes the bug by moving those two callbacks to the after_setup_theme action, which is the appropriate action to initialize theme features.

Props karl94, hellofromTonya, joemcgill, flixos90.
Fixes #59732.
See #18298, #53397, #54597.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r56932 r57009  
    522522// Theme.
    523523add_action( 'setup_theme', 'create_initial_theme_features', 0 );
    524 add_action( 'setup_theme', '_add_default_theme_supports', 1 );
     524add_action( 'after_setup_theme', '_add_default_theme_supports', 1 );
    525525add_action( 'wp_loaded', '_custom_header_background_just_in_time' );
    526526add_action( 'wp_head', '_custom_logo_header_styles' );
     
    719719add_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' );
    720720add_action( 'wp_footer', 'the_block_template_skip_link' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_block_template_skip_link().
    721 add_action( 'setup_theme', 'wp_enable_block_templates' );
     721add_action( 'after_setup_theme', 'wp_enable_block_templates', 1 );
    722722add_action( 'wp_loaded', '_add_template_loader_filters' );
    723723
  • trunk/src/wp-includes/theme.php

    r56765 r57009  
    43364336
    43374337/**
    4338  * Adds default theme supports for block themes when the 'setup_theme' action fires.
    4339  *
    4340  * See {@see 'setup_theme'}.
     4338 * Adds default theme supports for block themes when the 'after_setup_theme' action fires.
     4339 *
     4340 * See {@see 'after_setup_theme'}.
    43414341 *
    43424342 * @since 5.9.0
  • trunk/tests/phpunit/tests/block-template.php

    r56621 r57009  
    1616        switch_theme( 'block-theme' );
    1717        do_action( 'setup_theme' );
     18        do_action( 'after_setup_theme' );
    1819    }
    1920
  • trunk/tests/phpunit/tests/theme.php

    r56974 r57009  
    747747     * @ticket 54597
    748748     * @ticket 54731
     749     * @ticket 59732
    749750     *
    750751     * @dataProvider data_block_theme_has_default_support
     
    775776        );
    776777
    777         do_action( 'setup_theme' );
     778        do_action( 'after_setup_theme' );
    778779
    779780        $this->assertTrue(
     
    859860     *
    860861     * @ticket 54597
     862     * @ticket 59732
    861863     *
    862864     * @covers ::_add_default_theme_supports
     
    873875        );
    874876
    875         do_action( 'setup_theme' );
     877        do_action( 'after_setup_theme' );
    876878
    877879        $this->assertTrue(
Note: See TracChangeset for help on using the changeset viewer.