Themes: Show Preview button for block themes on Add Themes screen#11184
Themes: Show Preview button for block themes on Add Themes screen#11184sanketio wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Description
After installing a block theme from Appearance → Themes → Add New Theme, the "Preview" button was missing — only "Activate" appeared. Classic themes correctly showed both "Activate" and "Live Preview". This inconsistency was present across all tabs and search results.
The root cause is threefold:
wp_ajax_install_theme()was always sendingcustomizeUrlpointing to the classic Customizer (customize.php) for all themes, including block themes. Block themes don't support the Customizer, so the button was either broken or absent.wp_ajax_query_themes()(the on-load data for all theme cards) was sendingsite-editor.phpfor installed block themes, but without thewp_theme_preview=<slug>query parameter. Without it, clicking Preview would open the Site Editor for the currently active theme instead of the selected one.The Underscore.js template in
theme-install.phphad a blanket<# if ( ! data.block_theme ) { #>guard added by #54878 in 2022 to prevent pointing block themes at the Customizer. That suppression was never updated after context-aware Site Editor preview URLs became available.Changes
wp-admin/includes/ajax-actions.php— two functions:wp_ajax_install_theme(): For block themes, sendssite-editor.php?wp_theme_preview=<slug>&return=...instead of the classic Customizer URL. Mirrors the existing logic inclass-theme-installer-skin.phpused by the non-AJAX full-page install path. Capability check also broadened to allow block themes regardless of thecustomizecap.wp_ajax_query_themes(): Addswp_theme_preview=<slug>to the Site Editor URL for already-installed block themes shown on page load, so the button actually previews the correct theme.wp-admin/theme-install.php:Previewlink (noload-customize); classic themes keepLive Previewwithload-customize.js/_enqueues/wp/updates.js:installThemeSuccess(): Checksresponse.blockThemewhen replacing the.previewbutton post-install. Block themes get a plainPreview<a>without theload-customizeclass (which triggers Customizer-specific JS); classic themes are unchanged.Testing Instructions
Prerequisites: A WordPress install with at least one classic theme and one block theme available but not yet installed.
Block theme — AJAX install path
Classic theme — AJAX install path
Already-installed block theme cards (page-load path)
No regression — full-page install path
wp-admin/update.php?action=install-theme&theme=<slug>(non-AJAX install).class-theme-installer-skin.php.Active block theme
Trac ticket: https://core.trac.wordpress.org/ticket/64729
Use of AI Tools
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.