ManageSubscriptionBlock.php
1 week ago
MarketingOptinBlock.php
2 years ago
NewsletterBlock.php
1 month ago
PostEditorBlock.php
1 week ago
SubscriptionFormBlock.php
6 months ago
WooCommerceBlocksIntegration.php
2 years ago
index.php
3 years ago
PostEditorBlock.php
93 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\PostEditorBlocks; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Config\Env; |
| 9 | use MailPoet\Config\Renderer; |
| 10 | use MailPoet\WP\Functions as WPFunctions; |
| 11 | |
| 12 | class PostEditorBlock { |
| 13 | /** @var Renderer */ |
| 14 | private $renderer; |
| 15 | |
| 16 | /** @var WPFunctions */ |
| 17 | private $wp; |
| 18 | |
| 19 | /** @var SubscriptionFormBlock */ |
| 20 | private $subscriptionFormBlock; |
| 21 | |
| 22 | /** @var NewsletterBlock */ |
| 23 | private $newsletterBlock; |
| 24 | |
| 25 | /** @var ManageSubscriptionBlock */ |
| 26 | private $manageSubscriptionBlock; |
| 27 | |
| 28 | public function __construct( |
| 29 | Renderer $renderer, |
| 30 | WPFunctions $wp, |
| 31 | SubscriptionFormBlock $subscriptionFormBlock, |
| 32 | NewsletterBlock $newsletterBlock, |
| 33 | ManageSubscriptionBlock $manageSubscriptionBlock |
| 34 | ) { |
| 35 | $this->renderer = $renderer; |
| 36 | $this->wp = $wp; |
| 37 | $this->subscriptionFormBlock = $subscriptionFormBlock; |
| 38 | $this->newsletterBlock = $newsletterBlock; |
| 39 | $this->manageSubscriptionBlock = $manageSubscriptionBlock; |
| 40 | } |
| 41 | |
| 42 | public function init() { |
| 43 | $this->subscriptionFormBlock->init(); |
| 44 | $this->newsletterBlock->init(); |
| 45 | $this->manageSubscriptionBlock->init(); |
| 46 | |
| 47 | if ($this->wp->isAdmin()) { |
| 48 | $this->initAdmin(); |
| 49 | } else { |
| 50 | $this->initFrontend(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | private function initAdmin() { |
| 55 | $this->wp->addAction('enqueue_block_editor_assets', [$this, 'enqueueAssets']); |
| 56 | $this->subscriptionFormBlock->initAdmin(); |
| 57 | $this->newsletterBlock->initAdmin(); |
| 58 | $this->manageSubscriptionBlock->initAdmin(); |
| 59 | } |
| 60 | |
| 61 | public function enqueueAssets() { |
| 62 | $this->wp->wpEnqueueScript( |
| 63 | 'mailpoet-block-form-block-js', |
| 64 | Env::$assetsUrl . '/dist/js/' . $this->renderer->getJsAsset('post_editor_block.js'), |
| 65 | [ |
| 66 | 'wp-api-fetch', |
| 67 | 'wp-blocks', |
| 68 | 'wp-components', |
| 69 | 'wp-element', |
| 70 | 'wp-i18n', |
| 71 | 'wp-server-side-render', |
| 72 | 'wp-block-editor', |
| 73 | 'wp-url', |
| 74 | ], |
| 75 | Env::$version, |
| 76 | true |
| 77 | ); |
| 78 | |
| 79 | $this->wp->wpEnqueueStyle( |
| 80 | 'mailpoetblock-form-block-css', |
| 81 | Env::$assetsUrl . '/dist/css/' . $this->renderer->getCssAsset('mailpoet-post-editor-block.css'), |
| 82 | ['wp-edit-blocks'], |
| 83 | Env::$version |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | private function initFrontend() { |
| 88 | $this->subscriptionFormBlock->initFrontend(); |
| 89 | $this->newsletterBlock->initFrontend(); |
| 90 | $this->manageSubscriptionBlock->initFrontend(); |
| 91 | } |
| 92 | } |
| 93 |