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
MarketingOptinBlock.php
83 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\PostEditorBlocks; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface; |
| 9 | use MailPoet\Config\Env; |
| 10 | use MailPoet\WP\Functions as WPFunctions; |
| 11 | |
| 12 | /** |
| 13 | * Class MarketingOptinBlock |
| 14 | * |
| 15 | * Class for integrating marketing optin block with WooCommerce Checkout. |
| 16 | */ |
| 17 | class MarketingOptinBlock implements IntegrationInterface { |
| 18 | /** @var array */ |
| 19 | private $options; |
| 20 | |
| 21 | /** @var WPFunctions */ |
| 22 | private $wp; |
| 23 | |
| 24 | public function __construct( |
| 25 | array $options, |
| 26 | WPFunctions $wp |
| 27 | ) { |
| 28 | $this->options = $options; |
| 29 | $this->wp = $wp; |
| 30 | } |
| 31 | |
| 32 | public function get_name(): string { // phpcs:ignore PSR1.Methods.CamelCapsMethodName |
| 33 | return 'mailpoet'; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Register block scripts and assets. |
| 38 | */ |
| 39 | public function initialize() { |
| 40 | $script_asset_path = Env::$assetsPath . '/dist/js/marketing-optin-block/marketing-optin-block-frontend.asset.php'; |
| 41 | $script_asset = file_exists($script_asset_path) |
| 42 | ? require $script_asset_path |
| 43 | : [ |
| 44 | 'dependencies' => [], |
| 45 | 'version' => Env::$version, |
| 46 | ]; |
| 47 | $this->wp->wpRegisterScript( |
| 48 | 'mailpoet-marketing-optin-block-frontend', |
| 49 | Env::$assetsUrl . '/dist/js/marketing-optin-block/marketing-optin-block-frontend.js', |
| 50 | $script_asset['dependencies'], |
| 51 | $script_asset['version'], |
| 52 | true |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns an array of script handles to enqueue in the frontend context. |
| 58 | * |
| 59 | * @return string[] |
| 60 | */ |
| 61 | public function get_script_handles() { // phpcs:ignore |
| 62 | return ['mailpoet-marketing-optin-block-frontend']; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns an array of script handles to enqueue in the editor context. |
| 67 | * |
| 68 | * @return string[] |
| 69 | */ |
| 70 | public function get_editor_script_handles() { // phpcs:ignore |
| 71 | return []; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * An array of key, value pairs of data made available to the block on the client side. |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | public function get_script_data() { // phpcs:ignore |
| 80 | return $this->options; |
| 81 | } |
| 82 | } |
| 83 |