<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52371] trunk: Customize: Overlay incompatible banner for block themes.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52371">52371</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52371","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>hellofromTonya</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-12-14 15:31:14 +0000 (Tue, 14 Dec 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/changeset/41648">[41648]</a>, <a href="https://core.trac.wordpress.org/changeset/41893">[41893]</a>, <a href="https://core.trac.wordpress.org/changeset/52279">[52279]</a>.

Props antonvlasenko, costdev, hellofromTonya, jffng, joyously, noisysocks, poena, shaunandrews.
Fixes <a href="https://core.trac.wordpress.org/ticket/54549">#54549</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesthemephp">trunk/src/wp-admin/includes/theme.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizemanagerphp">trunk/src/wp-includes/class-wp-customize-manager.php</a></li>
<li><a href="#trunksrcwpincludescustomizeclasswpcustomizethemecontrolphp">trunk/src/wp-includes/customize/class-wp-customize-theme-control.php</a></li>
<li><a href="#trunktestsphpunittestsajaxCustomizeManagerphp">trunk/tests/phpunit/tests/ajax/CustomizeManager.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesthemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/theme.php     2021-12-14 14:59:33 UTC (rev 52370)
+++ trunk/src/wp-admin/includes/theme.php       2021-12-14 15:31:14 UTC (rev 52371)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1005,6 +1005,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                                ?>
</span><span class="cx" style="display: block; padding: 0 10px">                                                        <# } #>
</span><span class="cx" style="display: block; padding: 0 10px">                                                </p></div>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        <# } 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>
</ins><span class="cx" style="display: block; padding: 0 10px">                                         <# } #>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        <p class="theme-description">{{{ data.description }}}</p>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1025,10 +1040,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                <# } #>
</span><span class="cx" style="display: block; padding: 0 10px">                                        <?php } ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        <# if ( data.compatibleWP && data.compatiblePHP ) { #>
-                                               <button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 <# if ( data.blockTheme ) { #>
+                                               <?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>
+                                               <# } #>
</ins><span class="cx" style="display: block; padding: 0 10px">                                         <# } else { #>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                <button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         <# 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>
+                                               <# } #>
</ins><span class="cx" style="display: block; padding: 0 10px">                                         <# } #>
</span><span class="cx" style="display: block; padding: 0 10px">                                <# } else { #>
</span><span class="cx" style="display: block; padding: 0 10px">                                        <# if ( data.compatibleWP && data.compatiblePHP ) { #>
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizemanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-manager.php      2021-12-14 14:59:33 UTC (rev 52370)
+++ trunk/src/wp-includes/class-wp-customize-manager.php        2021-12-14 15:31:14 UTC (rev 52371)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5808,10 +5808,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( 'installed' === $theme_action ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // Load all installed themes from wp_prepare_themes_for_js().
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $themes = array( 'themes' => wp_prepare_themes_for_js() );
-                       foreach ( $themes['themes'] as &$theme ) {
-                               $theme['type']   = 'installed';
-                               $theme['active'] = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $themes = array( 'themes' => array() );
+                       foreach ( wp_prepare_themes_for_js() as $theme ) {
+                               $theme['type']      = 'installed';
+                               $theme['active']    = ( isset( $_POST['customized_theme'] ) && $_POST['customized_theme'] === $theme['id'] );
+                               $themes['themes'][] = $theme;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                } elseif ( 'wporg' === $theme_action ) {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpincludescustomizeclasswpcustomizethemecontrolphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/customize/class-wp-customize-theme-control.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/customize/class-wp-customize-theme-control.php      2021-12-14 14:59:33 UTC (rev 52370)
+++ trunk/src/wp-includes/customize/class-wp-customize-theme-control.php        2021-12-14 15:31:14 UTC (rev 52371)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -242,17 +242,47 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                </div>
</span><span class="cx" style="display: block; padding: 0 10px">                                <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
</span><span class="cx" style="display: block; padding: 0 10px">                        <# } else if ( 'installed' === data.theme.type ) { #>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <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>
-                                               <# } #>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <# if ( data.theme.blockTheme ) { #>
+                                       <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.actions.activate ) { #>
+                                                               <?php
+                                                                       /* 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>
</ins><span class="cx" style="display: block; padding: 0 10px">                                         </div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                </div>
-                               <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 <div class="notice notice-error notice-alt"><p>
+                                       <?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>
+                               <# } #>
</ins><span class="cx" style="display: block; padding: 0 10px">                         <# } else { #>
</span><span class="cx" style="display: block; padding: 0 10px">                                <div class="theme-id-container">
</span><span class="cx" style="display: block; padding: 0 10px">                                        <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
</span></span></pre></div>
<a id="trunktestsphpunittestsajaxCustomizeManagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/ajax/CustomizeManager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/ajax/CustomizeManager.php       2021-12-14 14:59:33 UTC (rev 52370)
+++ trunk/tests/phpunit/tests/ajax/CustomizeManager.php 2021-12-14 15:31:14 UTC (rev 52371)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -714,4 +714,49 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertFalse( $this->_last_response_parsed['success'] );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Test request for retrieving installed themes.
+        *
+        * @ticket 54549
+        * @covers WP_Customize_Manager::handle_load_themes_request
+        */
+       public function test_wp_ajax_customize_load_themes_action() {
+               $arguments = array(
+                       'changeset_uuid'     => false,
+                       'settings_previewed' => true,
+                       'branching'          => false,
+               );
+               new WP_Customize_Manager( $arguments );
+               wp_set_current_user( self::$admin_user_id );
+               $nonce                 = wp_create_nonce( 'switch_themes' );
+               $_POST['nonce']        = $nonce;
+               $_GET['nonce']         = $nonce;
+               $_REQUEST['nonce']     = $nonce;
+               $_POST['theme_action'] = 'installed';
+               $this->make_ajax_call( 'customize_load_themes' );
+               $response = $this->_last_response_parsed;
+               $this->assertIsArray( $response, 'Response is not an array' );
+
+               $this->assertArrayHasKey( 'success', $response, 'Response must have a "success" key' );
+               $this->assertTrue( $response['success'], 'Response was not "success"' );
+
+               $this->assertArrayHasKey( 'data', $response, 'Response must have a "data" key' );
+               $this->assertIsArray( $response['data'], 'The response "data" is not an array' );
+               $this->assertArrayHasKey( 'themes', $response['data'], 'The response data must have a "themes" key' );
+               $this->assertIsArray( $response['data']['themes'], 'Themes data is not an array' );
+               $this->assertNotEmpty( $response['data']['themes'], 'Themes data must not be empty' );
+
+               foreach ( $response['data']['themes'] as $theme ) {
+                       $this->assertIsArray( $theme, 'Theme is not an array' );
+                       $this->assertNotEmpty( $theme, 'Theme data must not be empty' );
+                       $this->assertArrayHasKey( 'id', $theme, 'Theme data must have an "id" key' );
+                       $this->assertNotEmpty( $theme['id'], 'Theme id cannot be empty' );
+
+                       $this->assertArrayHasKey( 'name', $theme, 'Theme data must have a "name" key' );
+                       $this->assertNotEmpty( $theme['name'], 'Theme name cannot be empty' );
+
+                       $this->assertArrayHasKey( 'blockTheme', $theme, 'Themes data must include information about blocks support' );
+               }
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>