From 3eef498b3f1be7204e241a2114eb845b650ccd61 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 12:41:25 +0200 Subject: [PATCH 01/28] BP: Add Theme Previews for block themes #50030 --- src/wp-settings.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-settings.php b/src/wp-settings.php index 26d2662f6b88b..dea39a9f45ce6 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -254,6 +254,7 @@ require ABSPATH . WPINC . '/admin-bar.php'; require ABSPATH . WPINC . '/class-wp-application-passwords.php'; require ABSPATH . WPINC . '/rest-api.php'; +require ABSPATH . WPINC . '/theme-previews.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-request.php'; From fa4b2e511e039f63f0412f6b1312cc791cd6fb9e Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 12:41:41 +0200 Subject: [PATCH 02/28] BP: Add Theme Previews for block themes #50030 --- src/wp-admin/includes/theme-previews.php | 129 +++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/wp-admin/includes/theme-previews.php diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php new file mode 100644 index 0000000000000..5671274925765 --- /dev/null +++ b/src/wp-admin/includes/theme-previews.php @@ -0,0 +1,129 @@ +errors() ) ) { + return sanitize_text_field( $preview_stylesheet ); + } + + return $current_stylesheet; +} + +/** + * Filters the blog option to return the parent theme directory for the previewed theme. + * + * @param string $current_stylesheet The current theme directory. + * @return string The previewed theme directory. + */ +function gutenberg_theme_preview_template( $current_stylesheet = null ) { + $preview_stylesheet = ! empty( $_GET['theme_preview'] ) ? $_GET['theme_preview'] : null; + $wp_theme = wp_get_theme( $preview_stylesheet ); + if ( ! is_wp_error( $wp_theme->errors() ) ) { + return sanitize_text_field( $wp_theme->get_template() ); + } + + return $current_stylesheet; +} + +/** + * Adds a middleware to the REST API to set the theme for the preview. + */ +function gutenberg_attach_theme_preview_middleware() { + wp_add_inline_script( + 'wp-api-fetch', + sprintf( + 'wp.apiFetch.use( wp.apiFetch.createThemePreviewMiddleware( %s ) );', + wp_json_encode( sanitize_text_field( $_GET['theme_preview'] ) ) + ), + 'after' + ); +} + +/** + * Temporary function to add a live preview button to block themes. + * Remove when https://core.trac.wordpress.org/ticket/58190 lands. + */ +function add_live_preview_button() { + global $pagenow; + if ( 'themes.php' === $pagenow ) { + ?> + + + + Date: Fri, 16 Jun 2023 12:46:46 +0200 Subject: [PATCH 03/28] BP: Theme Preview: Restrict to admin users #50335 --- src/wp-admin/includes/theme-previews.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 5671274925765..263b6f44a3191 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -14,7 +14,7 @@ function gutenberg_theme_preview_stylesheet( $current_stylesheet = null ) { $preview_stylesheet = ! empty( $_GET['theme_preview'] ) ? $_GET['theme_preview'] : null; $wp_theme = wp_get_theme( $preview_stylesheet ); - if ( ! is_wp_error( $wp_theme->errors() ) ) { + if ( ! is_wp_error( $wp_theme->errors() ) && current_user_can( 'switch_themes' ) ) { return sanitize_text_field( $preview_stylesheet ); } @@ -30,7 +30,7 @@ function gutenberg_theme_preview_stylesheet( $current_stylesheet = null ) { function gutenberg_theme_preview_template( $current_stylesheet = null ) { $preview_stylesheet = ! empty( $_GET['theme_preview'] ) ? $_GET['theme_preview'] : null; $wp_theme = wp_get_theme( $preview_stylesheet ); - if ( ! is_wp_error( $wp_theme->errors() ) ) { + if ( ! is_wp_error( $wp_theme->errors() ) && current_user_can( 'switch_themes' ) ) { return sanitize_text_field( $wp_theme->get_template() ); } @@ -41,6 +41,11 @@ function gutenberg_theme_preview_template( $current_stylesheet = null ) { * Adds a middleware to the REST API to set the theme for the preview. */ function gutenberg_attach_theme_preview_middleware() { + // Don't allow non-admins to preview themes. + if ( ! current_user_can( 'switch_themes' ) ) { + return; + } + wp_add_inline_script( 'wp-api-fetch', sprintf( From 2c48f38529d7a6630fb5cb6545135e3c93ccd1b7 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 12:49:13 +0200 Subject: [PATCH 04/28] BP: Refactor theme previews #50338 --- src/wp-admin/includes/theme-previews.php | 39 +++++++++++------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 263b6f44a3191..6c6db0ce03b2f 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -6,32 +6,27 @@ */ /** - * Filters the blog option to return the directory for the previewed theme. + * Filters the blog option to return the path for the previewed theme. * - * @param string $current_stylesheet The current theme directory. - * @return string The previewed theme directory. + * @param string $current_stylesheet The current theme's stylesheet or template path. + * @return string The previewed theme's stylesheet or template path. */ -function gutenberg_theme_preview_stylesheet( $current_stylesheet = null ) { - $preview_stylesheet = ! empty( $_GET['theme_preview'] ) ? $_GET['theme_preview'] : null; - $wp_theme = wp_get_theme( $preview_stylesheet ); - if ( ! is_wp_error( $wp_theme->errors() ) && current_user_can( 'switch_themes' ) ) { - return sanitize_text_field( $preview_stylesheet ); +function gutenberg_get_theme_preview_path( $current_stylesheet = null ) { + // Don't allow non-admins to preview themes. + if ( ! current_user_can( 'switch_themes' ) ) { + return; } - return $current_stylesheet; -} - -/** - * Filters the blog option to return the parent theme directory for the previewed theme. - * - * @param string $current_stylesheet The current theme directory. - * @return string The previewed theme directory. - */ -function gutenberg_theme_preview_template( $current_stylesheet = null ) { $preview_stylesheet = ! empty( $_GET['theme_preview'] ) ? $_GET['theme_preview'] : null; $wp_theme = wp_get_theme( $preview_stylesheet ); - if ( ! is_wp_error( $wp_theme->errors() ) && current_user_can( 'switch_themes' ) ) { - return sanitize_text_field( $wp_theme->get_template() ); + if ( ! is_wp_error( $wp_theme->errors() ) ) { + if ( current_filter() === 'stylesheet' ) { + $theme_path = $wp_theme->get_stylesheet(); + } elseif ( current_filter() === 'template' ) { + $theme_path = $wp_theme->get_template(); + } + + return sanitize_text_field( $theme_path ); } return $current_stylesheet; @@ -124,8 +119,8 @@ function block_theme_activate_nonce() { * Attaches filters to enable theme previews in the Site Editor. */ if ( ! empty( $_GET['theme_preview'] ) ) { - add_filter( 'stylesheet', 'gutenberg_theme_preview_stylesheet' ); - add_filter( 'template', 'gutenberg_theme_preview_template' ); + add_filter( 'stylesheet', 'gutenberg_get_theme_preview_path' ); + add_filter( 'template', 'gutenberg_get_theme_preview_path' ); add_filter( 'init', 'gutenberg_attach_theme_preview_middleware' ); } From 7658703826dc6d25e6757dd01431caacf3f08ecf Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 12:50:24 +0200 Subject: [PATCH 05/28] BP: Theme Previews: Fix refactor #50354 --- src/wp-admin/includes/theme-previews.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 6c6db0ce03b2f..43bb549cd969f 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -20,10 +20,10 @@ function gutenberg_get_theme_preview_path( $current_stylesheet = null ) { $preview_stylesheet = ! empty( $_GET['theme_preview'] ) ? $_GET['theme_preview'] : null; $wp_theme = wp_get_theme( $preview_stylesheet ); if ( ! is_wp_error( $wp_theme->errors() ) ) { - if ( current_filter() === 'stylesheet' ) { - $theme_path = $wp_theme->get_stylesheet(); - } elseif ( current_filter() === 'template' ) { + if ( current_filter() === 'template' ) { $theme_path = $wp_theme->get_template(); + } else { + $theme_path = $wp_theme->get_stylesheet(); } return sanitize_text_field( $theme_path ); @@ -104,7 +104,7 @@ function addLivePreviewButton() { * Adds a nonce for the theme activation link. */ function block_theme_activate_nonce() { - $nonce_handle = 'switch-theme_' . gutenberg_theme_preview_stylesheet(); + $nonce_handle = 'switch-theme_' . gutenberg_get_theme_preview_path(); ?> - - - Date: Fri, 16 Jun 2023 15:39:32 +0200 Subject: [PATCH 14/28] phpcs --- src/wp-admin/includes/theme-previews.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 59a30086485cf..a2edaf588edbf 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -39,7 +39,7 @@ function wp_attach_theme_preview_middleware() { if ( ! current_user_can( 'switch_themes' ) ) { return; } - + wp_add_inline_script( 'wp-api-fetch', sprintf( @@ -57,4 +57,4 @@ function wp_attach_theme_preview_middleware() { add_filter( 'stylesheet', 'wp_get_theme_preview_path' ); add_filter( 'template', 'wp_get_theme_preview_path' ); add_filter( 'init', 'wp_attach_theme_preview_middleware' ); -} \ No newline at end of file +} From 1270e3efa4e86b6ec27eda43f1ba403cc9660002 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 16:06:20 +0200 Subject: [PATCH 15/28] moved file to the correct place --- src/{wp-admin/includes => wp-includes}/theme-previews.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{wp-admin/includes => wp-includes}/theme-previews.php (100%) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-includes/theme-previews.php similarity index 100% rename from src/wp-admin/includes/theme-previews.php rename to src/wp-includes/theme-previews.php From 8339d079455385c47f036b0e3b26620e344dfc8b Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 16:40:55 +0200 Subject: [PATCH 16/28] Revert "moved file to the correct place" This reverts commit ab55297724bcfa0c87cef490f073d86070d2c3d0. --- src/{wp-includes => wp-admin/includes}/theme-previews.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{wp-includes => wp-admin/includes}/theme-previews.php (100%) diff --git a/src/wp-includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php similarity index 100% rename from src/wp-includes/theme-previews.php rename to src/wp-admin/includes/theme-previews.php From bf1eafae3a1a720ef9cce41cfeef3aeb889c90a8 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Fri, 16 Jun 2023 16:42:55 +0200 Subject: [PATCH 17/28] changed the include of the file --- src/wp-admin/includes/admin.php | 1 + src/wp-settings.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/admin.php b/src/wp-admin/includes/admin.php index ce2ec0c68b855..4930e92b71ed1 100644 --- a/src/wp-admin/includes/admin.php +++ b/src/wp-admin/includes/admin.php @@ -71,6 +71,7 @@ /** WordPress Theme Administration API */ require_once ABSPATH . 'wp-admin/includes/theme.php'; +require_once ABSPATH . 'wp-admin/includes/theme-previews.php'; /** WordPress Privacy Functions */ require_once ABSPATH . 'wp-admin/includes/privacy-tools.php'; diff --git a/src/wp-settings.php b/src/wp-settings.php index dea39a9f45ce6..26d2662f6b88b 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -254,7 +254,6 @@ require ABSPATH . WPINC . '/admin-bar.php'; require ABSPATH . WPINC . '/class-wp-application-passwords.php'; require ABSPATH . WPINC . '/rest-api.php'; -require ABSPATH . WPINC . '/theme-previews.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php'; require ABSPATH . WPINC . '/rest-api/class-wp-rest-request.php'; From ffbcbb03407d9b918edcce8b662c2a038b613ee3 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Mon, 19 Jun 2023 11:05:40 +0200 Subject: [PATCH 18/28] improved dockblocks --- src/wp-admin/includes/theme-previews.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index a2edaf588edbf..911e907704366 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -8,6 +8,8 @@ /** * Filters the blog option to return the path for the previewed theme. * + * @since 6.3.0 + * * @param string $current_stylesheet The current theme's stylesheet or template path. * @return string The previewed theme's stylesheet or template path. */ @@ -33,6 +35,8 @@ function wp_get_theme_preview_path( $current_stylesheet = null ) { /** * Adds a middleware to `apiFetch` to set the theme for the preview. + * + * @since 6.3.0 */ function wp_attach_theme_preview_middleware() { // Don't allow non-admins to preview themes. @@ -52,6 +56,9 @@ function wp_attach_theme_preview_middleware() { /** * Attaches filters to enable theme previews in the Site Editor. + * + * @since 6.3.0 + * */ if ( ! empty( $_GET['wp_theme_preview'] ) ) { add_filter( 'stylesheet', 'wp_get_theme_preview_path' ); From 596545c90262dd10bb79b3d7401e2b951add8163 Mon Sep 17 00:00:00 2001 From: MaggieCabrera Date: Mon, 19 Jun 2023 11:32:29 +0200 Subject: [PATCH 19/28] check that is not null --- src/wp-admin/includes/theme.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index b3c34370711e0..938d2b34f1bfc 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -718,13 +718,15 @@ function wp_prepare_themes_for_js( $themes = null ) { } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { $customize_action = wp_customize_url( $slug ); } - $customize_action = add_query_arg( - array( - 'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), - ), - $customize_action - ); - $customize_action = esc_url( $customize_action ); + if ($customize_action !== null) { + $customize_action = add_query_arg( + array( + 'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), + ), + $customize_action + ); + $customize_action = esc_url( $customize_action ); + } $update_requires_wp = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null; $update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null; From 86be1266fbf1cebdf401622db85ba67844e3c341 Mon Sep 17 00:00:00 2001 From: scruffian Date: Wed, 21 Jun 2023 11:50:20 +0100 Subject: [PATCH 20/28] remove whitespace --- src/wp-admin/includes/theme-previews.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 911e907704366..1959e6ef3b85e 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -9,7 +9,7 @@ * Filters the blog option to return the path for the previewed theme. * * @since 6.3.0 - * + * * @param string $current_stylesheet The current theme's stylesheet or template path. * @return string The previewed theme's stylesheet or template path. */ @@ -35,7 +35,7 @@ function wp_get_theme_preview_path( $current_stylesheet = null ) { /** * Adds a middleware to `apiFetch` to set the theme for the preview. - * + * * @since 6.3.0 */ function wp_attach_theme_preview_middleware() { @@ -56,9 +56,9 @@ function wp_attach_theme_preview_middleware() { /** * Attaches filters to enable theme previews in the Site Editor. - * + * * @since 6.3.0 - * + * */ if ( ! empty( $_GET['wp_theme_preview'] ) ) { add_filter( 'stylesheet', 'wp_get_theme_preview_path' ); From 4a6581dee957afbd8ac57d3e9e3fb5d84a592d73 Mon Sep 17 00:00:00 2001 From: Maggie Date: Wed, 21 Jun 2023 14:03:00 +0200 Subject: [PATCH 21/28] Update src/wp-admin/includes/theme-previews.php Co-authored-by: Ben Dwyer --- src/wp-admin/includes/theme-previews.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 1959e6ef3b85e..4727fb87788db 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -35,6 +35,7 @@ function wp_get_theme_preview_path( $current_stylesheet = null ) { /** * Adds a middleware to `apiFetch` to set the theme for the preview. + * This adds a `wp_theme_preview` URL parameter to API requests from the Site Editor, so they also respond as if the theme is set to the value of the parameter. * * @since 6.3.0 */ From e6182be5a94946055c90ce44117ea12ca901efc0 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 23 Jun 2023 14:05:43 +1000 Subject: [PATCH 22/28] Fix PHPCS --- src/wp-admin/includes/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 938d2b34f1bfc..b4fff713ed63e 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -718,7 +718,7 @@ function wp_prepare_themes_for_js( $themes = null ) { } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { $customize_action = wp_customize_url( $slug ); } - if ($customize_action !== null) { + if ( null !== $customize_action ) { $customize_action = add_query_arg( array( 'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), From 88c7f9dae5f2ad573a2c992c8ba4da8a7fd47fd7 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 23 Jun 2023 14:08:42 +1000 Subject: [PATCH 23/28] Remove extra space --- src/wp-admin/includes/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index b4fff713ed63e..efcfffae756c7 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -718,7 +718,7 @@ function wp_prepare_themes_for_js( $themes = null ) { } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { $customize_action = wp_customize_url( $slug ); } - if ( null !== $customize_action ) { + if ( null !== $customize_action ) { $customize_action = add_query_arg( array( 'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), From 4c32603fbb5b020f7d24199647c338aa8d76802f Mon Sep 17 00:00:00 2001 From: scruffian Date: Fri, 23 Jun 2023 11:15:09 +0100 Subject: [PATCH 24/28] Move filters, change filter to an action and rename url param --- src/wp-admin/includes/admin-filters.php | 7 +++++++ src/wp-admin/includes/theme-previews.php | 12 ------------ src/wp-admin/includes/theme.php | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php index 33354cb073e32..8f364360fd8a9 100644 --- a/src/wp-admin/includes/admin-filters.php +++ b/src/wp-admin/includes/admin-filters.php @@ -168,3 +168,10 @@ // Append '(Draft)' to draft page titles in the privacy page dropdown. add_filter( 'list_pages', '_wp_privacy_settings_filter_draft_page_titles', 10, 2 ); + +// 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' ); +} diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 4727fb87788db..8682e82ef7eec 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -54,15 +54,3 @@ function wp_attach_theme_preview_middleware() { 'after' ); } - -/** - * Attaches filters to enable theme previews in the Site Editor. - * - * @since 6.3.0 - * - */ -if ( ! empty( $_GET['wp_theme_preview'] ) ) { - add_filter( 'stylesheet', 'wp_get_theme_preview_path' ); - add_filter( 'template', 'wp_get_theme_preview_path' ); - add_filter( 'init', 'wp_attach_theme_preview_middleware' ); -} diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index efcfffae756c7..82b9715631609 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -713,7 +713,7 @@ function wp_prepare_themes_for_js( $themes = null ) { if ( $is_block_theme && $can_edit_theme_options ) { $customize_action = admin_url( 'site-editor.php' ); if ( $current_theme !== $slug ) { - $customize_action = add_query_arg( 'theme_preview', $slug, $customize_action ); + $customize_action = add_query_arg( 'wp_theme_preview', $slug, $customize_action ); } } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { $customize_action = wp_customize_url( $slug ); From f260cd566d86ec8a25243620e6474f05e14212ff Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Fri, 23 Jun 2023 11:22:50 +0100 Subject: [PATCH 25/28] Update src/wp-admin/includes/theme-previews.php Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- src/wp-admin/includes/theme-previews.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index 8682e82ef7eec..f3df5122face3 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -18,7 +18,7 @@ function wp_get_theme_preview_path( $current_stylesheet = null ) { return $current_stylesheet; } - $preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? $_GET['wp_theme_preview'] : null; + $preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null; $wp_theme = wp_get_theme( $preview_stylesheet ); if ( ! is_wp_error( $wp_theme->errors() ) ) { if ( current_filter() === 'template' ) { From 391e296729809ae1df5bb1856216b393377c6e0e Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Fri, 23 Jun 2023 11:22:58 +0100 Subject: [PATCH 26/28] Update src/wp-admin/includes/theme-previews.php Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- src/wp-admin/includes/theme-previews.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/includes/theme-previews.php b/src/wp-admin/includes/theme-previews.php index f3df5122face3..55a3679096dd4 100644 --- a/src/wp-admin/includes/theme-previews.php +++ b/src/wp-admin/includes/theme-previews.php @@ -49,7 +49,7 @@ function wp_attach_theme_preview_middleware() { 'wp-api-fetch', sprintf( 'wp.apiFetch.use( wp.apiFetch.createThemePreviewMiddleware( %s ) );', - wp_json_encode( sanitize_text_field( $_GET['wp_theme_preview'] ) ) + wp_json_encode( sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) ) ), 'after' ); From a21719119d59012f1a981a536b511ffa1148d6f1 Mon Sep 17 00:00:00 2001 From: scruffian Date: Fri, 23 Jun 2023 11:25:48 +0100 Subject: [PATCH 27/28] Add back customize check --- src/wp-admin/themes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index 7e6d5b33effc7..0fc8b4b12e65e 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -555,7 +555,7 @@ ?> From 9971a7aa33b904870575a1e5e2675c6842f5aacd Mon Sep 17 00:00:00 2001 From: Maggie Date: Mon, 26 Jun 2023 11:36:16 +0200 Subject: [PATCH 28/28] Update src/wp-admin/themes.php Co-authored-by: Felix Arntz --- src/wp-admin/themes.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index 0fc8b4b12e65e..351fe93dbd975 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -555,7 +555,8 @@ ?>