From 4b35425d7b1960f0e8f8dc4800e4794abe4971d2 Mon Sep 17 00:00:00 2001
From: Tonya Mork
Date: Tue, 14 Dec 2021 15:31:14 +0000
Subject: [PATCH] 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.
git-svn-id: https://develop.svn.wordpress.org/trunk@52371 602fd350-edb4-49c9-b593-d223f7449a82
---
src/wp-admin/includes/theme.php | 31 ++++++++++--
.../class-wp-customize-manager.php | 9 ++--
.../class-wp-customize-theme-control.php | 50 +++++++++++++++----
tests/phpunit/tests/ajax/CustomizeManager.php | 45 +++++++++++++++++
4 files changed, 118 insertions(+), 17 deletions(-)
diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php
index 1e4828b3c1..8e98854afc 100644
--- a/src/wp-admin/includes/theme.php
+++ b/src/wp-admin/includes/theme.php
@@ -1005,6 +1005,21 @@ function customize_themes_print_templates() {
?>
<# } #>
+
+ <# if ( data.actions.activate ) { #>
+ activate this theme, and use the Site Editor to customize it.' ),
+ '{{{ data.actions.activate }}}'
+ );
+ ?>
+ <# } #>
+
+
+ <# if ( data.theme.actions.activate ) { #>
+ activate this theme, and use the Site Editor to customize it.' ),
+ '{{{ data.theme.actions.activate }}}'
+ );
+ ?>
+ <# } #>
+
diff --git a/tests/phpunit/tests/ajax/CustomizeManager.php b/tests/phpunit/tests/ajax/CustomizeManager.php
index 16a029c4f4..82dcc13c67 100644
--- a/tests/phpunit/tests/ajax/CustomizeManager.php
+++ b/tests/phpunit/tests/ajax/CustomizeManager.php
@@ -714,4 +714,49 @@ class Tests_Ajax_CustomizeManager extends WP_Ajax_UnitTestCase {
$this->assertFalse( $this->_last_response_parsed['success'] );
$this->assertSame( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
}
+
+ /**
+ * 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' );
+ }
+ }
}