Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/js/_enqueues/wp/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,8 +1818,14 @@

if ( response.customizeUrl ) {

// Transform the 'Preview' button into a 'Live Preview' button.
// Transform the 'Preview' button into a 'Live Preview' or 'Preview' (block theme) button.
$message.siblings( '.preview' ).replaceWith( function () {
if ( response.blockTheme ) {
return $( '<a>' )
.attr( 'href', response.customizeUrl )
.addClass( 'button' )
.text( __( 'Preview' ) );
}
return $( '<a>' )
.attr( 'href', response.customizeUrl )
.addClass( 'button load-customize' )
Expand Down
50 changes: 35 additions & 15 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3709,15 +3709,25 @@ function wp_ajax_query_themes() {
// We only care about installed themes.
$theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme();

if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug );
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && ( $theme->block_theme || current_user_can( 'customize' ) ) ) {
if ( $theme->block_theme ) {
$customize_url = add_query_arg(
array(
'wp_theme_preview' => urlencode( $theme->slug ),
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
admin_url( 'site-editor.php' )
);
} else {
$customize_url = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
wp_customize_url( $theme->slug )
);
}

$theme->customize_url = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
$customize_url
);
$theme->customize_url = $customize_url;
}

$theme->name = wp_kses( $theme->name, $themes_allowedtags );
Expand Down Expand Up @@ -4262,13 +4272,23 @@ function wp_ajax_install_theme() {
$theme = wp_get_theme( $slug );
$status['blockTheme'] = $theme->is_block_theme();

if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$status['customizeUrl'] = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
wp_customize_url( $slug )
);
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && ( $status['blockTheme'] || current_user_can( 'customize' ) ) ) {
if ( $status['blockTheme'] ) {
$status['customizeUrl'] = add_query_arg(
array(
'wp_theme_preview' => urlencode( $slug ),
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
admin_url( 'site-editor.php' )
);
} else {
$status['customizeUrl'] = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
wp_customize_url( $slug )
);
}
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/wp-admin/theme-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@
<# } #>
<# if ( data.customize_url ) { #>
<# if ( ! data.active ) { #>
<# if ( ! data.block_theme ) { #>
<# if ( data.block_theme ) { #>
<a class="button" href="{{ data.customize_url }}"><?php _e( 'Preview' ); ?></a>
<# } else { #>
<a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
<# } #>
<# } else { #>
Expand Down
Loading