Make WordPress Core

Changeset 56758 for branches/6.3


Ignore:
Timestamp:
10/02/2023 10:54:29 PM (14 months ago)
Author:
danielbachhuber
Message:

Editor: Prevent possibility of a fatal error when previewing block themes.

Ensures that preview callbacks attached to the stylesheet and template filters do not run before pluggable.php has been included. These callbacks need functionality from pluggable.php.

Props scruffian, johnbillion, SergeyBiryukov, okat, azaozz.
Merges [56529] and [56757] to the 6.3 branch.
Fixes #59000.

Location:
branches/6.3
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-includes/default-filters.php

    r56140 r56758  
    534534add_action( 'transition_post_status', '_wp_keep_alive_customize_changeset_dependent_auto_drafts', 20, 3 );
    535535
     536// Block Theme Previews.
     537add_action( 'plugins_loaded', 'wp_initialize_theme_preview_hooks', 1 );
     538
    536539// Calendar widget cache.
    537540add_action( 'save_post', 'delete_get_calendar_cache' );
  • branches/6.3/src/wp-includes/theme-previews.php

    r56218 r56758  
    7676}
    7777
    78 // Attaches filters to enable theme previews in the Site Editor.
    79 if ( ! empty( $_GET['wp_theme_preview'] ) ) {
    80     add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
    81     add_filter( 'template', 'wp_get_theme_preview_path' );
    82     add_action( 'init', 'wp_attach_theme_preview_middleware' );
    83     add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
     78/**
     79 * Add filters and actions to enable Block Theme Previews in the Site Editor.
     80 *
     81 * The filters and actions should be added after `pluggable.php` is included as they may
     82 * trigger code that uses `current_user_can()` which requires functionality from `pluggable.php`.
     83 *
     84 * @since 6.3.2
     85 */
     86function wp_initialize_theme_preview_hooks() {
     87    if ( ! empty( $_GET['wp_theme_preview'] ) ) {
     88        add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
     89        add_filter( 'template', 'wp_get_theme_preview_path' );
     90        add_action( 'init', 'wp_attach_theme_preview_middleware' );
     91        add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
     92    }
    8493}
  • branches/6.3/tests/phpunit/tests/theme-previews.php

    r56529 r56758  
    1818    public function test_initialize_theme_preview_hooks() {
    1919        $_GET['wp_theme_preview'] = 'twentytwentythree';
    20         do_action( 'plugins_loaded' ); // Ensure `plugins_loaded` triggers `initialize_theme_preview_hooks`.
     20        do_action( 'plugins_loaded' ); // Ensure `plugins_loaded` triggers `wp_initialize_theme_preview_hooks`.
    2121
    2222        $this->assertEquals( has_filter( 'stylesheet', 'wp_get_theme_preview_path' ), 10 );
Note: See TracChangeset for help on using the changeset viewer.