Ensure the template theme is always an object.

Sending it as an empty array was causing that deepmerge in emailCss hook was returning null.
It was happening for the general-email template which has no theme file
[MAILPOET-5641]
This commit is contained in:
Rostislav Wolny
2024-05-06 14:04:04 +02:00
committed by Aschepikov
parent c3dcc13f2c
commit 1fab8a31f3

View File

@@ -12,6 +12,7 @@ use WP_Error;
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
class Templates { class Templates {
const MAILPOET_EMAIL_META_THEME_TYPE = 'mailpoet_email_theme'; const MAILPOET_EMAIL_META_THEME_TYPE = 'mailpoet_email_theme';
const MAILPOET_TEMPLATE_EMPTY_THEME = ['version' => 2]; // The version 2 is important to merge themes correctly
private string $templateDirectory; private string $templateDirectory;
private string $pluginSlug; private string $pluginSlug;
@@ -95,7 +96,7 @@ class Templates {
} }
} }
return $this->themeJson[$templateSlug] ?? []; return $this->themeJson[$templateSlug] ?? self::MAILPOET_TEMPLATE_EMPTY_THEME;
} }
public function getBlockFileTemplate($return, $templateId, $template_type) { public function getBlockFileTemplate($return, $templateId, $template_type) {
@@ -261,7 +262,7 @@ class Templates {
], ],
'single' => true, 'single' => true,
'type' => 'object', 'type' => 'object',
'default' => ['version' => 2], // The version 2 is important to merge themes correctly 'default' => self::MAILPOET_TEMPLATE_EMPTY_THEME,
] ]
); );