Customize: Overlay incompatible banner for block themes.

Starting in 5.9, block themes are not compatible with (do not support) Customizer; rather, they use the Site Editor. Viewing installed themes in Customizer, this commit adds an overlay message to alert users and give them a way to activate the block theme. Clicking on the "Activate" button activates the block theme and redirects back to the Appearance > Themes interface, where the user can then enter the Site Editor for customization.

Non-block themes are not affected by this change and continue to work in Customizer.

Follow-up to [41648], [41893], [52279].

Props antonvlasenko, costdev, hellofromTonya, jffng, joyously, noisysocks, poena, shaunandrews.
Fixes #54549.
Built from https://develop.svn.wordpress.org/trunk@52371


git-svn-id: http://core.svn.wordpress.org/trunk@51963 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-12-14 15:33:01 +00:00
parent dfef2c917f
commit edf755823b
4 changed files with 74 additions and 18 deletions

View File

@ -1005,6 +1005,21 @@ function customize_themes_print_templates() {
?> ?>
<# } #> <# } #>
</p></div> </p></div>
<# } else if ( ! data.active && data.blockTheme ) { #>
<div class="notice notice-error notice-alt notice-large"><p>
<?php
_e( 'This theme doesn\'t support Customizer.' );
?>
<# if ( data.actions.activate ) { #>
<?php
printf(
/* translators: %s: URL to the themes page (also it activates the theme). */
' ' . __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ),
'{{{ data.actions.activate }}}'
);
?>
<# } #>
</p></div>
<# } #> <# } #>
<p class="theme-description">{{{ data.description }}}</p> <p class="theme-description">{{{ data.description }}}</p>
@ -1025,10 +1040,20 @@ function customize_themes_print_templates() {
<# } #> <# } #>
<?php } ?> <?php } ?>
<# if ( data.compatibleWP && data.compatiblePHP ) { #> <# if ( data.blockTheme ) { #>
<button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button> <?php
/* translators: %s: Theme name. */
$aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
?>
<# if ( data.compatibleWP && data.compatiblePHP && data.actions.activate ) { #>
<a href="{{{ data.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
<# } #>
<# } else { #> <# } else { #>
<button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button> <# if ( data.compatibleWP && data.compatiblePHP ) { #>
<button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button>
<# } else { #>
<button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button>
<# } #>
<# } #> <# } #>
<# } else { #> <# } else { #>
<# if ( data.compatibleWP && data.compatiblePHP ) { #> <# if ( data.compatibleWP && data.compatiblePHP ) { #>

View File

@ -5808,10 +5808,11 @@ final class WP_Customize_Manager {
if ( 'installed' === $theme_action ) { if ( 'installed' === $theme_action ) {
// Load all installed themes from wp_prepare_themes_for_js(). // Load all installed themes from wp_prepare_themes_for_js().
$themes = array( 'themes' => wp_prepare_themes_for_js() ); $themes = array( 'themes' => array() );
foreach ( $themes['themes'] as &$theme ) { foreach ( wp_prepare_themes_for_js() as $theme ) {
$theme['type'] = 'installed'; $theme['type'] = 'installed';
$theme['active'] = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] ); $theme['active'] = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] );
$themes['themes'][] = $theme;
} }
} elseif ( 'wporg' === $theme_action ) { } elseif ( 'wporg' === $theme_action ) {

View File

@ -242,17 +242,47 @@ class WP_Customize_Theme_Control extends WP_Customize_Control {
</div> </div>
<div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div> <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
<# } else if ( 'installed' === data.theme.type ) { #> <# } else if ( 'installed' === data.theme.type ) { #>
<div class="theme-id-container"> <# if ( data.theme.blockTheme ) { #>
<h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-id-container">
<div class="theme-actions"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
<# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #> <div class="theme-actions">
<button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button> <# if ( data.theme.actions.activate ) { #>
<# } else { #> <?php
<button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button> /* translators: %s: Theme name. */
<# } #> $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
?>
<a href="{{{ data.theme.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
<# } #>
</div>
</div> </div>
</div> <div class="notice notice-error notice-alt"><p>
<div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div> <?php
_e( 'This theme doesn\'t support Customizer.' );
?>
<# if ( data.theme.actions.activate ) { #>
<?php
echo ' ';
printf(
/* translators: %s: URL to the themes page (also it activates the theme). */
__( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ),
'{{{ data.theme.actions.activate }}}'
);
?>
<# } #>
</p></div>
<# } else { #>
<div class="theme-id-container">
<h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
<div class="theme-actions">
<# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #>
<button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button>
<# } else { #>
<button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button>
<# } #>
</div>
</div>
<div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
<# } #>
<# } else { #> <# } else { #>
<div class="theme-id-container"> <div class="theme-id-container">
<h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-beta2-52370'; $wp_version = '5.9-beta2-52371';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.