Render email content in the editor and pass rendered HTML output to the emails custom post-type template
MAILPOET-6323
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
a28ff7da50
commit
26ea3a0d04
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet Email Editor package.
|
||||
* Template canvas file to render the emails custom post type.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
// get the rendered post HTML content.
|
||||
$template_html = apply_filters( 'mailpoet_email_editor_preview_post_template_html', get_post() );
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $template_html;
|
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
* Template canvas file to render the emails custom post type.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\EmailEditor\Engine\Renderer\Renderer;
|
||||
|
||||
/***
|
||||
* Generate html content for email editor post.
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception If the post is invalid.
|
||||
*/
|
||||
function mee_get_rendered_html(): string {
|
||||
$post = get_post();
|
||||
|
||||
if ( ! $post instanceof \WP_Post ) {
|
||||
throw new \Exception( esc_html__( 'Invalid post', 'mailpoet' ) );
|
||||
}
|
||||
|
||||
$subject = $post->post_title;
|
||||
$language = get_bloginfo( 'language' );
|
||||
|
||||
$renderer = ContainerWrapper::getInstance()->get( Renderer::class ); // TODO: Update implementation.
|
||||
|
||||
$rendered_data = $renderer->render(
|
||||
$post,
|
||||
$subject,
|
||||
__( 'Preview', 'mailpoet' ),
|
||||
$language
|
||||
);
|
||||
|
||||
return $rendered_data['html'];
|
||||
}
|
||||
|
||||
|
||||
$template_html = mee_get_rendered_html();
|
||||
|
||||
// We control those templates.
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $template_html;
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of the MailPoet plugin.
|
||||
* This file is part of the MailPoet Email Editor package.
|
||||
*
|
||||
* @package MailPoet\EmailEditor
|
||||
*/
|
||||
@@ -282,16 +282,18 @@ class Email_Editor {
|
||||
|
||||
$email_post_types = array_column( $this->get_post_types(), 'name' );
|
||||
|
||||
if ( in_array( $current_post_type, $email_post_types, true ) && locate_template( array( "single-$current_post_type.php" ) ) !== $template ) {
|
||||
/*
|
||||
* This is an email post
|
||||
* AND a 'single $post_type template' is not found on
|
||||
* theme or child theme directories, so load it
|
||||
* from our plugin directory.
|
||||
*/
|
||||
return __DIR__ . '/Templates/single-post-template.php';
|
||||
if ( ! in_array( $current_post_type, $email_post_types, true ) ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return $template;
|
||||
add_filter(
|
||||
'mailpoet_email_editor_preview_post_template_html',
|
||||
function ( $post ) {
|
||||
// Generate HTML content for email editor post.
|
||||
return $this->send_preview_email->render_html( $post );
|
||||
}
|
||||
);
|
||||
|
||||
return __DIR__ . '/Templates/single-email-post-template.php';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user