diff --git a/lib/compat/wordpress-6.3/theme-previews.php b/lib/compat/wordpress-6.3/theme-previews.php index d5334b319ff8a..eab05c5824b1f 100644 --- a/lib/compat/wordpress-6.3/theme-previews.php +++ b/lib/compat/wordpress-6.3/theme-previews.php @@ -17,7 +17,7 @@ function gutenberg_get_theme_preview_path( $current_stylesheet = null ) { return $current_stylesheet; } - $preview_stylesheet = ! empty( $_GET['gutenberg_theme_preview'] ) ? $_GET['gutenberg_theme_preview'] : null; + $preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? $_GET['wp_theme_preview'] : null; $wp_theme = wp_get_theme( $preview_stylesheet ); if ( ! is_wp_error( $wp_theme->errors() ) ) { if ( current_filter() === 'template' ) { @@ -45,7 +45,7 @@ function gutenberg_attach_theme_preview_middleware() { 'wp-api-fetch', sprintf( 'wp.apiFetch.use( wp.apiFetch.createThemePreviewMiddleware( %s ) );', - wp_json_encode( sanitize_text_field( $_GET['gutenberg_theme_preview'] ) ) + wp_json_encode( sanitize_text_field( $_GET['wp_theme_preview'] ) ) ), 'after' ); @@ -88,7 +88,7 @@ function addLivePreviewButton() { livePreviewButton.setAttribute('class', 'button button-primary'); livePreviewButton.setAttribute( 'href', - `/wp-admin/site-editor.php?gutenberg_theme_preview=${themePath}&return=themes.php` + `/wp-admin/site-editor.php?wp_theme_preview=${themePath}&return=themes.php` ); livePreviewButton.innerHTML = ''; themeInfo.querySelector('.theme-actions').appendChild(livePreviewButton); @@ -115,12 +115,13 @@ function block_theme_activate_nonce() { /** * Attaches filters to enable theme previews in the Site Editor. */ -if ( ! empty( $_GET['gutenberg_theme_preview'] ) ) { +if ( ! empty( $_GET['wp_theme_preview'] ) && ! function_exists( 'wp_get_theme_preview_path' ) ) { add_filter( 'stylesheet', 'gutenberg_get_theme_preview_path' ); add_filter( 'template', 'gutenberg_get_theme_preview_path' ); add_filter( 'init', 'gutenberg_attach_theme_preview_middleware' ); } -add_action( 'admin_head', 'block_theme_activate_nonce' ); -add_action( 'admin_print_footer_scripts', 'add_live_preview_button', 11 ); - +if ( ! function_exists( 'wp_get_theme_preview_path' ) ) { + add_action( 'admin_head', 'block_theme_activate_nonce' ); + add_action( 'admin_print_footer_scripts', 'add_live_preview_button', 11 ); +} diff --git a/packages/api-fetch/src/middlewares/theme-preview.js b/packages/api-fetch/src/middlewares/theme-preview.js index c8f4c0b7aeaf1..8ab21fc328476 100644 --- a/packages/api-fetch/src/middlewares/theme-preview.js +++ b/packages/api-fetch/src/middlewares/theme-preview.js @@ -4,7 +4,7 @@ import { addQueryArgs, hasQueryArg } from '@wordpress/url'; /** - * This appends a `gutenberg_theme_preview` parameter to the REST API request URL if + * This appends a `wp_theme_preview` parameter to the REST API request URL if * the admin URL contains a `theme` GET parameter. * * @param {Record} themePath @@ -13,19 +13,19 @@ import { addQueryArgs, hasQueryArg } from '@wordpress/url'; const createThemePreviewMiddleware = ( themePath ) => ( options, next ) => { if ( typeof options.url === 'string' && - ! hasQueryArg( options.url, 'gutenberg_theme_preview' ) + ! hasQueryArg( options.url, 'wp_theme_preview' ) ) { options.url = addQueryArgs( options.url, { - gutenberg_theme_preview: themePath, + wp_theme_preview: themePath, } ); } if ( typeof options.path === 'string' && - ! hasQueryArg( options.path, 'gutenberg_theme_preview' ) + ! hasQueryArg( options.path, 'wp_theme_preview' ) ) { options.path = addQueryArgs( options.path, { - gutenberg_theme_preview: themePath, + wp_theme_preview: themePath, } ); } diff --git a/packages/edit-site/src/components/routes/link.js b/packages/edit-site/src/components/routes/link.js index 1f386ef0bb3dc..3191e6b9c6f3a 100644 --- a/packages/edit-site/src/components/routes/link.js +++ b/packages/edit-site/src/components/routes/link.js @@ -37,7 +37,7 @@ export function useLink( params = {}, state, shouldReplace = false ) { if ( isPreviewingTheme() ) { params = { ...params, - gutenberg_theme_preview: currentlyPreviewingTheme(), + wp_theme_preview: currentlyPreviewingTheme(), }; } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js index c2fbc4ea480ef..d714ecb43b15d 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js @@ -67,7 +67,7 @@ export default function LeafMoreMenu( props ) { postType: attributes.type, postId: attributes.id, ...( isPreviewingTheme() && { - gutenberg_theme_preview: currentlyPreviewingTheme(), + wp_theme_preview: currentlyPreviewingTheme(), } ), } ); } @@ -76,7 +76,7 @@ export default function LeafMoreMenu( props ) { postType: 'page', postId: attributes.id, ...( isPreviewingTheme() && { - gutenberg_theme_preview: currentlyPreviewingTheme(), + wp_theme_preview: currentlyPreviewingTheme(), } ), } ); } diff --git a/packages/edit-site/src/utils/is-previewing-theme.js b/packages/edit-site/src/utils/is-previewing-theme.js index 4ce57bfdbc508..1a71c441f9925 100644 --- a/packages/edit-site/src/utils/is-previewing-theme.js +++ b/packages/edit-site/src/utils/is-previewing-theme.js @@ -5,14 +5,13 @@ import { getQueryArg } from '@wordpress/url'; export function isPreviewingTheme() { return ( - getQueryArg( window.location.href, 'gutenberg_theme_preview' ) !== - undefined + getQueryArg( window.location.href, 'wp_theme_preview' ) !== undefined ); } export function currentlyPreviewingTheme() { if ( isPreviewingTheme() ) { - return getQueryArg( window.location.href, 'gutenberg_theme_preview' ); + return getQueryArg( window.location.href, 'wp_theme_preview' ); } return null; } diff --git a/packages/edit-site/src/utils/use-activate-theme.js b/packages/edit-site/src/utils/use-activate-theme.js index 966705a7722e4..64654318274cd 100644 --- a/packages/edit-site/src/utils/use-activate-theme.js +++ b/packages/edit-site/src/utils/use-activate-theme.js @@ -31,7 +31,7 @@ export function useActivateTheme() { '&_wpnonce=' + window.BLOCK_THEME_ACTIVATE_NONCE; await window.fetch( activationURL ); - const { gutenberg_theme_preview: themePreview, ...params } = + const { wp_theme_preview: themePreview, ...params } = location.params; history.replace( params ); }