From a28ff7da505686e979b04ec48fc4dfc30c35fce2 Mon Sep 17 00:00:00 2001 From: Oluwaseun Olorunsola Date: Thu, 23 Jan 2025 15:27:50 +0100 Subject: [PATCH] Refactor `Send_Preview_Email` to add support for reusability MAILPOET-6323 --- .../src/Engine/class-send-preview-email.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/php/email-editor/src/Engine/class-send-preview-email.php b/packages/php/email-editor/src/Engine/class-send-preview-email.php index 934953f2ce..4c5f6656b5 100644 --- a/packages/php/email-editor/src/Engine/class-send-preview-email.php +++ b/packages/php/email-editor/src/Engine/class-send-preview-email.php @@ -58,8 +58,21 @@ class Send_Preview_Email { $email = $data['email']; $post_id = $data['postId']; - $post = $this->fetch_post( $post_id ); + $post = $this->fetch_post( $post_id ); + $subject = $post->post_title; + $email_html_content = $this->render_html( $post ); + + return $this->send_email( $email, $subject, $email_html_content ); + } + + /** + * Renders the HTML content of the post + * + * @param \WP_Post $post The WordPress post object. + * @return string + */ + public function render_html( $post ): string { $subject = $post->post_title; $language = get_bloginfo( 'language' ); @@ -70,9 +83,7 @@ class Send_Preview_Email { $language ); - $email_html_content = $rendered_data['html']; - - return $this->send_email( $email, $subject, $email_html_content ); + return $rendered_data['html']; } /**