From fcd2d517cdcf9c78a45414727ecde8638eda650f Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Fri, 24 Jan 2020 10:11:36 +0800 Subject: [PATCH] Onboarding: Allow any uploaded theme to be activated (https://github.com/woocommerce/woocommerce-admin/pull/3620) * Allow installed themes to be installed and activated * Filter themes on client-side by WC support and currently active * Run transient deletion hook during REST requests * Delete transient on theme switch for non-admin requests --- .../dashboard/profile-wizard/steps/theme/index.js | 8 +++++--- plugins/woocommerce-admin/src/Features/Onboarding.php | 11 +++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/theme/index.js b/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/theme/index.js index a5392cf492e..514d61a2613 100644 --- a/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/theme/index.js +++ b/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/theme/index.js @@ -236,9 +236,11 @@ class Theme extends Component { getThemes( activeTab = 'all' ) { const { uploadedThemes } = this.state; - const { themes = [] } = getSetting( 'onboarding', {} ); - themes.concat( uploadedThemes ); - const allThemes = [ ...themes, ...uploadedThemes ]; + const { activeTheme = '', themes = [] } = getSetting( 'onboarding', {} ); + const allThemes = [ + ...themes.filter( theme => theme.has_woocommerce_support || theme.slug === activeTheme ), + ...uploadedThemes, + ]; switch ( activeTab ) { case 'paid': diff --git a/plugins/woocommerce-admin/src/Features/Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php index d4ba89c1fe5..660a5ee83dd 100644 --- a/plugins/woocommerce-admin/src/Features/Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -76,6 +76,8 @@ class Onboarding { // Rest API hooks need to run before is_admin() checks. add_filter( 'woocommerce_rest_prepare_themes', array( $this, 'add_uploaded_theme_data' ) ); + add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) ); + add_action( 'after_switch_theme', array( $this, 'delete_themes_transient' ) ); // Add onboarding notes. new WC_Admin_Notes_Onboarding_Profiler(); @@ -92,8 +94,6 @@ class Onboarding { add_filter( 'woocommerce_component_settings_preload_endpoints', array( $this, 'add_preload_endpoints' ) ); add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) ); add_filter( 'woocommerce_admin_preload_settings', array( $this, 'preload_settings' ) ); - add_action( 'woocommerce_theme_installed', array( $this, 'delete_themes_transient' ) ); - add_action( 'after_switch_theme', array( $this, 'delete_themes_transient' ) ); add_action( 'current_screen', array( $this, 'finish_paypal_connect' ) ); add_action( 'current_screen', array( $this, 'finish_square_connect' ) ); add_action( 'current_screen', array( $this, 'add_help_tab' ), 60 ); @@ -236,12 +236,7 @@ class Onboarding { $active_theme = get_option( 'stylesheet' ); foreach ( $installed_themes as $slug => $theme ) { - $theme_data = self::get_theme_data( $theme ); - - if ( ! $theme_data['has_woocommerce_support'] && $active_theme !== $slug ) { - continue; - } - + $theme_data = self::get_theme_data( $theme ); $installed_themes = wp_get_themes(); $themes[ $slug ] = $theme_data; }