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.

Built from https://develop.svn.wordpress.org/branches/6.3@56758


git-svn-id: http://core.svn.wordpress.org/branches/6.3@56270 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
danielbachhuber 2023-10-02 22:56:24 +00:00
parent 578d633a14
commit 5b7940ecfd
3 changed files with 19 additions and 7 deletions

View File

@ -533,6 +533,9 @@ add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' );
add_action( 'delete_attachment', '_delete_attachment_theme_mod' );
add_action( 'transition_post_status', '_wp_keep_alive_customize_changeset_dependent_auto_drafts', 20, 3 );
// Block Theme Previews.
add_action( 'plugins_loaded', 'wp_initialize_theme_preview_hooks', 1 );
// Calendar widget cache.
add_action( 'save_post', 'delete_get_calendar_cache' );
add_action( 'delete_post', 'delete_get_calendar_cache' );

View File

@ -75,10 +75,19 @@ function wp_block_theme_activate_nonce() {
<?php
}
// Attaches filters to enable theme previews in the Site Editor.
if ( ! empty( $_GET['wp_theme_preview'] ) ) {
add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
add_filter( 'template', 'wp_get_theme_preview_path' );
add_action( 'init', 'wp_attach_theme_preview_middleware' );
add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
/**
* Add filters and actions to enable Block Theme Previews in the Site Editor.
*
* The filters and actions should be added after `pluggable.php` is included as they may
* trigger code that uses `current_user_can()` which requires functionality from `pluggable.php`.
*
* @since 6.3.2
*/
function wp_initialize_theme_preview_hooks() {
if ( ! empty( $_GET['wp_theme_preview'] ) ) {
add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
add_filter( 'template', 'wp_get_theme_preview_path' );
add_action( 'init', 'wp_attach_theme_preview_middleware' );
add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
}
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3.2-alpha-56737';
$wp_version = '6.3.2-alpha-56758';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.