diff --git a/packages/php/email-editor/src/Engine/Renderer/class-renderer.php b/packages/php/email-editor/src/Engine/Renderer/class-renderer.php index 87be1c3196..ab67a5d5ba 100644 --- a/packages/php/email-editor/src/Engine/Renderer/class-renderer.php +++ b/packages/php/email-editor/src/Engine/Renderer/class-renderer.php @@ -72,9 +72,9 @@ class Renderer { * @return array */ public function render( \WP_Post $post, string $subject, string $pre_header, string $language, $meta_robots = '' ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed - $template_id = get_stylesheet() . '//' . ( get_page_template_slug( $post ) ? get_page_template_slug( $post ) : 'email-general' ); + $template_slug = get_page_template_slug( $post ) ? get_page_template_slug( $post ) : 'email-general'; /** @var \WP_Block_Template $template */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan - $template = $this->templates->get_block_template( $template_id ); + $template = $this->templates->get_block_template( $template_slug ); $email_styles = $this->theme_controller->get_styles(); $template_html = $this->content_renderer->render( $post, $template ); 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 24e217628d..da03d533da 100644 --- a/packages/php/email-editor/src/Engine/Templates/class-templates.php +++ b/packages/php/email-editor/src/Engine/Templates/class-templates.php @@ -51,10 +51,12 @@ class Templates { /** * Get a block template by ID. * - * @param string $template_id The template ID. + * @param string $template_slug The template slug. * @return WP_Block_Template|null */ - public function get_block_template( $template_id ) { + public function get_block_template( $template_slug ) { + // Template id is always prefixed by active theme and get_stylesheet returns the active theme slug. + $template_id = get_stylesheet() . '//' . $template_slug; return get_block_template( $template_id ); } diff --git a/packages/php/email-editor/tests/integration/Engine/Templates/Templates_Test.php b/packages/php/email-editor/tests/integration/Engine/Templates/Templates_Test.php index a88954311c..f24878a4d7 100644 --- a/packages/php/email-editor/tests/integration/Engine/Templates/Templates_Test.php +++ b/packages/php/email-editor/tests/integration/Engine/Templates/Templates_Test.php @@ -35,12 +35,11 @@ class Templates_Test extends \MailPoetTest { * @return void */ public function testItCanFetchBlockTemplate(): void { - $template_id = get_stylesheet() . '//email-general'; // Templates id is prefixed with the theme name. - $template = $this->templates->get_block_template( $template_id ); + $template = $this->templates->get_block_template( 'email-general' ); self::assertInstanceOf( \WP_Block_Template::class, $template ); verify( $template->slug )->equals( 'email-general' ); - verify( $template->id )->equals( $template_id ); + verify( $template->id )->stringContainsString( 'email-general' ); verify( $template->title )->equals( 'General Email' ); verify( $template->description )->equals( 'A general template for emails.' ); }