From efb6136a701f0edec67da62adc5ae170df82f381 Mon Sep 17 00:00:00 2001 From: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Date: Mon, 21 Aug 2023 14:48:51 +0100 Subject: [PATCH] Fix/10530 Inconsistent new install behaviour for templates when using block themes (https://github.com/woocommerce/woocommerce-blocks/pull/10608) * Skipped requests regarding WP/WC setup, to avoid issues with the pages not existing yet when migrating page content to templates. * Skipped requests regarding WP-CLI to avoid issues with the pages not existing yet when migrating page content to templates. * Added check for woocommerce_db_version option * Add check for occurred migration to skip template injection * corrected if clause * Update src/BlockTemplatesController.php Co-authored-by: Mike Jolley * Added maintenance mode to migration exception. Added trace value to has_migrated options * Merge with new migration logic. * Set correct post terms for wp_template content * updated comment --------- Co-authored-by: Mike Jolley --- .../src/BlockTemplatesController.php | 7 +++++++ .../src/Templates/CartTemplate.php | 7 +++++++ .../src/Templates/CheckoutTemplate.php | 7 +++++++ .../src/Utils/BlockTemplateMigrationUtils.php | 12 ++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-blocks/src/BlockTemplatesController.php b/plugins/woocommerce-blocks/src/BlockTemplatesController.php index ba7d00ed286..377bf5002b5 100644 --- a/plugins/woocommerce-blocks/src/BlockTemplatesController.php +++ b/plugins/woocommerce-blocks/src/BlockTemplatesController.php @@ -1,6 +1,7 @@ get_placeholder_page(); return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name; diff --git a/plugins/woocommerce-blocks/src/Templates/CheckoutTemplate.php b/plugins/woocommerce-blocks/src/Templates/CheckoutTemplate.php index 000c6edbe18..02ac2a7420b 100644 --- a/plugins/woocommerce-blocks/src/Templates/CheckoutTemplate.php +++ b/plugins/woocommerce-blocks/src/Templates/CheckoutTemplate.php @@ -1,6 +1,8 @@ get_placeholder_page(); return null !== $placeholder && $post instanceof \WP_Post && $placeholder->post_name === $post->post_name; diff --git a/plugins/woocommerce-blocks/src/Utils/BlockTemplateMigrationUtils.php b/plugins/woocommerce-blocks/src/Utils/BlockTemplateMigrationUtils.php index 290a2847dfb..d87f042ede9 100644 --- a/plugins/woocommerce-blocks/src/Utils/BlockTemplateMigrationUtils.php +++ b/plugins/woocommerce-blocks/src/Utils/BlockTemplateMigrationUtils.php @@ -1,8 +1,6 @@ theme, 'wp_theme', ARRAY_A ); + + if ( ! $term ) { + $term = wp_insert_term( $template->theme, 'wp_theme' ); + } + $template_id = wp_insert_post( [ 'post_name' => $template->slug, @@ -150,6 +155,9 @@ class BlockTemplateMigrationUtils { ], true ); + + wp_set_post_terms( $template_id, array( $term['term_id'] ), 'wp_theme' ); + return $template_id && ! is_wp_error( $template_id ); }