Make WordPress Core


Ignore:
Timestamp:
10/02/2023 10:54:29 PM (19 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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • 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}
Note: See TracChangeset for help on using the changeset viewer.