Skip to content

Commit 2b00b04

Browse files
authored
Ensure that Site Editor templates are associated with the correct taxonomy (#1997)
Fixes #1996 While the bug might be in the WordPress-Importer itself, we can fix it by adding a filter that just ensures that the term will be created. I vote for adding this small intermediate fix even as in #1888 there is the plan to import WXRs differently in future. This is confusing behavior right now and we can fix it
1 parent 0314ce5 commit 2b00b04

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/playground/blueprints/src/lib/steps/import-wxr.ts

+19
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ export const importWxr: StepHandler<ImportWxrStep<File>> = async (
5959
return wp_slash($data);
6060
});
6161
62+
// Ensure that Site Editor templates are associated with the correct taxonomy.
63+
add_filter( 'wp_import_post_terms', function ( $terms, $post_id ) {
64+
foreach ( $terms as $post_term ) {
65+
if ( 'wp_theme' !== $term['taxonomy'] ) continue;
66+
$post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] );
67+
if ( ! $post_term ) {
68+
$post_term = wp_insert_term(
69+
$term['slug'],
70+
$term['taxonomy']
71+
);
72+
$term_id = $post_term['term_id'];
73+
} else {
74+
$term_id = $post_term->term_id;
75+
}
76+
wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ;
77+
}
78+
return $terms;
79+
}, 10, 2 );
80+
6281
$result = $importer->import( '/tmp/import.wxr' );
6382
`,
6483
});

0 commit comments

Comments
 (0)