From 132ffde58f05c729881497b5737a66ab09a39fe0 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Thu, 19 Dec 2024 15:45:54 +0100 Subject: [PATCH] Fix saving template associations with emails The original workaround was not working for templates that have edits saved in the DB. The problem was that when the template is saved in the DB the get_block_templates() returns WP_Block_Template object with post_types as null. It seems this association is not saved to DB in the core. [MAILPOET-6334] --- .../php/email-editor/src/Engine/Templates/class-templates.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/php/email-editor/src/Engine/Templates/class-templates.php b/packages/php/email-editor/src/Engine/Templates/class-templates.php index f70af63db3..0dc7453486 100644 --- a/packages/php/email-editor/src/Engine/Templates/class-templates.php +++ b/packages/php/email-editor/src/Engine/Templates/class-templates.php @@ -144,7 +144,9 @@ class Templates { } $block_templates = get_block_templates(); foreach ( $block_templates as $block_template ) { - if ( ! is_array( $block_template->post_types ) || ! array_intersect( $this->post_types, $block_template->post_types ) ) { + // Ideally we could check for supported post_types but there seems to be a bug and once a template has some edits and is stored in DB + // the core returns null for post_types. + if ( $block_template->plugin !== $this->template_prefix ) { continue; } $templates[ $block_template->slug ] = $block_template;