Skip to content

Commit c09b7fb

Browse files
committed
Themes: Restore 'Live Preview' button for block themes.
Note that the `return` query parameter is not yet functional in the Site Editor. See [WordPress/gutenberg#47934 Gutenberg#47934]. Follow-up to [52341], [52346], [52353], [52802]. Props ninomiho, mcsf, dhruval04, praful2111, mlaetitia1986. See #54578. Fixes #64159. git-svn-id: https://develop.svn.wordpress.org/trunk@61195 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 875e8e8 commit c09b7fb

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

src/wp-admin/includes/class-theme-installer-skin.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,24 @@ public function after() {
121121

122122
$install_actions = array();
123123

124-
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) && ! $theme_info->is_block_theme() ) {
125-
$customize_url = add_query_arg(
126-
array(
127-
'theme' => urlencode( $stylesheet ),
128-
'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
129-
),
130-
admin_url( 'customize.php' )
131-
);
124+
if ( current_user_can( 'edit_theme_options' ) && ( $theme_info->is_block_theme() || current_user_can( 'customize' ) ) ) {
125+
if ( $theme_info->is_block_theme() ) {
126+
$customize_url = add_query_arg(
127+
array(
128+
'wp_theme_preview' => urlencode( $stylesheet ),
129+
'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
130+
),
131+
admin_url( 'site-editor.php' )
132+
);
133+
} else {
134+
$customize_url = add_query_arg(
135+
array(
136+
'theme' => urlencode( $stylesheet ),
137+
'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
138+
),
139+
admin_url( 'customize.php' )
140+
);
141+
}
132142

133143
$install_actions['preview'] = sprintf(
134144
'<a href="%s" class="hide-if-no-customize load-customize">' .

src/wp-admin/themes.php

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@
645645
><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
646646

647647
<?php
648-
if ( ! $theme['blockTheme'] && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
648+
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
649649
/* translators: %s: Theme name. */
650650
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
651651
?>
@@ -1034,15 +1034,13 @@ function wp_theme_auto_update_setting_template() {
10341034
aria-label="<?php echo esc_attr( $aria_label ); ?>"
10351035
><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
10361036

1037-
<# if ( ! data.blockTheme ) { #>
1038-
<?php
1039-
/* translators: %s: Theme name. */
1040-
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
1041-
?>
1042-
<a class="button button-primary hide-if-no-customize disabled"
1043-
aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>"
1044-
><?php _e( 'Live Preview' ); ?></a>
1045-
<# } #>
1037+
<?php
1038+
/* translators: %s: Theme name. */
1039+
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
1040+
?>
1041+
<a class="button button-primary hide-if-no-customize disabled"
1042+
aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>"
1043+
><?php _e( 'Live Preview' ); ?></a>
10461044
<# } #>
10471045
<# } #>
10481046
</div>
@@ -1261,16 +1259,14 @@ function wp_theme_auto_update_setting_template() {
12611259

12621260
<div class="inactive-theme">
12631261
<# if ( data.compatibleWP && data.compatiblePHP ) { #>
1264-
<# if ( ! data.blockTheme ) { #>
1265-
<?php
1266-
/* translators: %s: Theme name. */
1267-
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
1268-
?>
1269-
<a class="button button-primary load-customize hide-if-no-customize"
1270-
href="{{{ data.actions.customize }}}"
1271-
aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>"
1272-
><?php _e( 'Live Preview' ); ?></a>
1273-
<# } #>
1262+
<?php
1263+
/* translators: %s: Theme name. */
1264+
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
1265+
?>
1266+
<a class="button button-primary load-customize hide-if-no-customize"
1267+
href="{{{ data.actions.customize }}}"
1268+
aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>"
1269+
><?php _e( 'Live Preview' ); ?></a>
12741270

12751271
<# if ( data.actions.activate ) { #>
12761272
<?php
@@ -1283,15 +1279,13 @@ function wp_theme_auto_update_setting_template() {
12831279
><?php _e( 'Activate' ); ?></a>
12841280
<# } #>
12851281
<# } else { #>
1286-
<# if ( ! data.blockTheme ) { #>
1287-
<?php
1288-
/* translators: %s: Theme name. */
1289-
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
1290-
?>
1291-
<a class="button button-primary hide-if-no-customize disabled"
1292-
aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>"
1293-
><?php _e( 'Live Preview' ); ?></a>
1294-
<# } #>
1282+
<?php
1283+
/* translators: %s: Theme name. */
1284+
$live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
1285+
?>
1286+
<a class="button button-primary hide-if-no-customize disabled"
1287+
aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>"
1288+
><?php _e( 'Live Preview' ); ?></a>
12951289

12961290
<# if ( data.actions.activate ) { #>
12971291
<?php

0 commit comments

Comments
 (0)