Engine
4 weeks ago
Integrations
4 weeks ago
Validator
1 year ago
class-bootstrap.php
2 months ago
class-container.php
7 months ago
class-email-css-inliner.php
7 months ago
class-email-editor-container.php
3 months ago
class-package.php
1 year ago
exceptions.php
1 year ago
class-bootstrap.php
113 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This file is part of the WooCommerce Email Editor package |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\EmailEditor |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | namespace Automattic\WooCommerce\EmailEditor; |
| 10 | |
| 11 | use Automattic\WooCommerce\EmailEditor\Engine\Email_Editor; |
| 12 | use Automattic\WooCommerce\EmailEditor\Integrations\Core\Initializer as CoreEmailEditorIntegration; |
| 13 | use Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Coupon_Code_Generator; |
| 14 | use Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Initializer as WooCommerceEmailEditorIntegration; |
| 15 | |
| 16 | /** |
| 17 | * Bootstrap class for initializing the Email Editor functionality. |
| 18 | */ |
| 19 | class Bootstrap { |
| 20 | |
| 21 | /** |
| 22 | * Email editor instance. |
| 23 | * |
| 24 | * @var Email_Editor |
| 25 | */ |
| 26 | private $email_editor; |
| 27 | |
| 28 | /** |
| 29 | * Core email editor integration instance. |
| 30 | * |
| 31 | * @var CoreEmailEditorIntegration |
| 32 | */ |
| 33 | private $core_email_editor_integration; |
| 34 | |
| 35 | /** |
| 36 | * WooCommerce email editor integration instance. |
| 37 | * |
| 38 | * @var WooCommerceEmailEditorIntegration |
| 39 | */ |
| 40 | private $woocommerce_email_editor_integration; |
| 41 | |
| 42 | /** |
| 43 | * Constructor. |
| 44 | * |
| 45 | * @param Email_Editor $email_editor Email editor instance. |
| 46 | * @param CoreEmailEditorIntegration $core_email_editor_integration Core email editor integration instance. |
| 47 | * @param WooCommerceEmailEditorIntegration $woocommerce_email_editor_integration WooCommerce email editor integration instance. |
| 48 | */ |
| 49 | public function __construct( |
| 50 | Email_Editor $email_editor, |
| 51 | CoreEmailEditorIntegration $core_email_editor_integration, |
| 52 | WooCommerceEmailEditorIntegration $woocommerce_email_editor_integration |
| 53 | ) { |
| 54 | $this->email_editor = $email_editor; |
| 55 | $this->core_email_editor_integration = $core_email_editor_integration; |
| 56 | $this->woocommerce_email_editor_integration = $woocommerce_email_editor_integration; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Initialize the email editor functionality. |
| 61 | */ |
| 62 | public function init(): void { |
| 63 | add_action( |
| 64 | 'init', |
| 65 | array( |
| 66 | $this, |
| 67 | 'initialize', |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | add_filter( |
| 72 | 'woocommerce_email_editor_initialized', |
| 73 | array( |
| 74 | $this, |
| 75 | 'setup_email_editor_integrations', |
| 76 | ) |
| 77 | ); |
| 78 | add_filter( |
| 79 | 'block_type_metadata_settings', |
| 80 | array( $this->core_email_editor_integration, 'update_block_settings' ), |
| 81 | 10, |
| 82 | 1 |
| 83 | ); |
| 84 | |
| 85 | if ( class_exists( 'WooCommerce' ) ) { |
| 86 | add_filter( |
| 87 | 'block_type_metadata_settings', |
| 88 | array( $this->woocommerce_email_editor_integration, 'update_block_settings' ), |
| 89 | 10, |
| 90 | 1 |
| 91 | ); |
| 92 | |
| 93 | $coupon_generator = new Coupon_Code_Generator(); |
| 94 | $coupon_generator->init(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Initialize the email editor. |
| 100 | */ |
| 101 | public function initialize(): void { |
| 102 | $this->email_editor->initialize(); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Setup email editor integrations. |
| 107 | */ |
| 108 | public function setup_email_editor_integrations(): bool { |
| 109 | $this->core_email_editor_integration->initialize(); |
| 110 | return true; // PHPStan expect returning a value from the filter. |
| 111 | } |
| 112 | } |
| 113 |