From 5b13ae083529237179f6c7ee9957659a0bf6ae69 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Thu, 14 Nov 2024 09:26:33 +0100 Subject: [PATCH] Ensure that Site Editor templates are associated with the correct taxonomy --- .../blueprints/src/lib/steps/import-wxr.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/playground/blueprints/src/lib/steps/import-wxr.ts b/packages/playground/blueprints/src/lib/steps/import-wxr.ts index 1b6611526e..1169d133d3 100644 --- a/packages/playground/blueprints/src/lib/steps/import-wxr.ts +++ b/packages/playground/blueprints/src/lib/steps/import-wxr.ts @@ -59,6 +59,25 @@ export const importWxr: StepHandler> = async ( return wp_slash($data); }); + // Ensure that Site Editor templates are associated with the correct taxonomy. + add_filter( 'wp_import_post_terms', function ( $terms, $post_id ) { + foreach ( $terms as $post_term ) { + if ( 'wp_theme' !== $term['taxonomy'] ) continue; + $post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] ); + if ( ! $post_term ) { + $post_term = wp_insert_term( + $term['slug'], + $term['taxonomy'] + ); + $term_id = $post_term['term_id']; + } else { + $term_id = $post_term->term_id; + } + wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ; + } + return $terms; + }, 10, 2 ); + $result = $importer->import( '/tmp/import.wxr' ); `, });