diff --git a/mailpoet/lib/DI/ContainerConfigurator.php b/mailpoet/lib/DI/ContainerConfigurator.php index 1071780947..189366dc40 100644 --- a/mailpoet/lib/DI/ContainerConfigurator.php +++ b/mailpoet/lib/DI/ContainerConfigurator.php @@ -353,6 +353,7 @@ class ContainerConfigurator implements IContainerConfigurator { $container->autowire(\MailPoet\EmailEditor\Integrations\Core\Initializer::class)->setPublic(true); $container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor::class)->setPublic(true); $container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\EmailApiController::class)->setPublic(true); + $container->autowire(\MailPoet\EmailEditor\Integrations\MailPoet\Blocks\BlockTypesController::class)->setPublic(true); // Features $container->autowire(\MailPoet\Features\FeaturesController::class)->setPublic(true); $container->autowire(\MailPoet\Features\FeatureFlagsController::class)->setPublic(true); diff --git a/mailpoet/lib/EmailEditor/Engine/Renderer/Templates/email-general.html b/mailpoet/lib/EmailEditor/Engine/Renderer/Templates/email-general.html index 888d7460ff..4ab0ef8971 100644 --- a/mailpoet/lib/EmailEditor/Engine/Renderer/Templates/email-general.html +++ b/mailpoet/lib/EmailEditor/Engine/Renderer/Templates/email-general.html @@ -1 +1 @@ - + diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php b/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php index 0049f7cb90..8ce09ee9ad 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Initializer.php @@ -24,7 +24,6 @@ class Initializer { $blocksRegistry->addBlockRenderer('core/image', new Renderer\Blocks\Image()); $blocksRegistry->addBlockRenderer('core/buttons', new Renderer\Blocks\Buttons(new FlexLayoutRenderer())); $blocksRegistry->addBlockRenderer('core/button', new Renderer\Blocks\Button()); - $blocksRegistry->addBlockRenderer('core/post-content', new Renderer\Blocks\PostContent()); } /** diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/PostContent.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/PostContent.php deleted file mode 100644 index 72f0e5616f..0000000000 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/PostContent.php +++ /dev/null @@ -1,18 +0,0 @@ -renderContent($blockContent, $parsedBlock, $settingsController); - } - - protected function renderContent(string $blockContent, array $parsedBlock, SettingsController $settingsController): string { - global $post; - - /** This filter is documented in wp-includes/post-template.php */ - return apply_filters('the_content', str_replace(']]>', ']]>', $post->post_content)); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps - } -} diff --git a/mailpoet/lib/EmailEditor/Integrations/MailPoet/Blocks/BlockTypes/AbstractBlock.php b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Blocks/BlockTypes/AbstractBlock.php new file mode 100644 index 0000000000..f7eebacc37 --- /dev/null +++ b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Blocks/BlockTypes/AbstractBlock.php @@ -0,0 +1,63 @@ +registerBlockType(); + } + + /** + * Get the block type. + * + * @return string + */ + protected function getBlockType() { + return $this->namespace . '/' . $this->blockName; + } + + protected function parseRenderCallbackAttributes($attributes): array { + return is_a($attributes, 'WP_Block') ? $attributes->attributes : $attributes; + } + + /** + * The default render_callback for all blocks. + */ + public function renderCallback($attributes = [], $content = '', $block = null): string { + $render_callback_attributes = $this->parseRenderCallbackAttributes($attributes); + return $this->render($render_callback_attributes, $content, $block); + } + + /** + * Registers the block type with WordPress. + */ + protected function registerBlockType() { + $metadata_path = __DIR__ . '/' . $this->blockName . '/block.json'; + $block_settings = [ + 'render_callback' => [$this, 'renderCallback'], + 'api_version' => '2', + ]; + + register_block_type_from_metadata( + $metadata_path, + $block_settings + ); + } + + /** + * Render the block. Extended by children. + * + * @param array $attributes Block attributes. + * @param string $content Block content. + * @param WP_Block $block Block instance. + * @return string Rendered block type output. + */ + protected function render($attributes, $content, $block) { + return $content; + } +} diff --git a/mailpoet/lib/EmailEditor/Integrations/MailPoet/Blocks/BlockTypes/EmailContent.php b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Blocks/BlockTypes/EmailContent.php new file mode 100644 index 0000000000..b7d35cf168 --- /dev/null +++ b/mailpoet/lib/EmailEditor/Integrations/MailPoet/Blocks/BlockTypes/EmailContent.php @@ -0,0 +1,35 @@ +', ']]>', $post->post_content)); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps + + return sprintf( + '