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
6 changes: 6 additions & 0 deletions src/js/_enqueues/wp/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,12 @@

// Transform the 'Preview' button into a 'Live Preview' button.
$message.siblings( '.preview' ).replaceWith( function () {
if ( response.blockTheme ) {
return $( '<a>' )
.attr( 'href', response.customizeUrl )
.addClass( 'button' )
.text( __( 'Live 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( 'Live Preview' ); ?></a>
<# } else { #>
<a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
<# } #>
<# } else { #>
Expand Down
Loading