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
This commit is contained in:
Joshua T Flowers 2020-01-24 10:11:36 +08:00 committed by GitHub
parent 2438885f09
commit fcd2d517cd
2 changed files with 8 additions and 11 deletions

View File

@ -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':

View File

@ -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 );
@ -237,11 +237,6 @@ class Onboarding {
foreach ( $installed_themes as $slug => $theme ) {
$theme_data = self::get_theme_data( $theme );
if ( ! $theme_data['has_woocommerce_support'] && $active_theme !== $slug ) {
continue;
}
$installed_themes = wp_get_themes();
$themes[ $slug ] = $theme_data;
}