From eaeda35de1726b9dfb80045f1074a268313e783c Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Mon, 17 Mar 2025 13:01:24 +0000 Subject: [PATCH] Editor: Support site preview mode for the Site Editor. This allows the Site Editor to load a preview of the site as an `IFRAME_REQUEST` by checking for a `wp_site_preview` query param. By setting the `IFRAME_REQUEST` constant when loading the preview, the site's admin bar and some third party plugin overlays will not be shown in the preview. Props wildworks, joemcgill, peterwilsoncc, presstoke, mamaduka, johnbillion, faisal03. Fixes #63076. git-svn-id: https://develop.svn.wordpress.org/trunk@60003 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/block-editor.php | 18 ++++++++++++++++++ src/wp-includes/default-filters.php | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 007c713190..2bd9f2dfbf 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -856,3 +856,21 @@ function get_classic_theme_supports_block_editor_settings() { return $theme_settings; } + +/** + * Initialize site preview. + * + * This function sets IFRAME_REQUEST to true if the site preview parameter is set. + * + * @since 6.8.0 + */ +function wp_initialize_site_preview_hooks() { + if ( + ! defined( 'IFRAME_REQUEST' ) && + isset( $_GET['wp_site_preview'] ) && + 1 === (int) $_GET['wp_site_preview'] && + current_user_can( 'edit_theme_options' ) + ) { + define( 'IFRAME_REQUEST', true ); + } +} diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index d143652dd8..f6d80b091c 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -551,6 +551,9 @@ add_action( 'transition_post_status', '_wp_keep_alive_customize_changeset_depend // Block Theme Previews. add_action( 'plugins_loaded', 'wp_initialize_theme_preview_hooks', 1 ); +// Site preview for Classic Theme. +add_action( 'init', 'wp_initialize_site_preview_hooks', 1 ); + // Calendar widget cache. add_action( 'save_post', 'delete_get_calendar_cache' ); add_action( 'delete_post', 'delete_get_calendar_cache' );