| 1 |
<?php |
| 2 |
/** |
| 3 |
* Email Template Service Provider |
| 4 |
* |
| 5 |
* @package Forge12\DoubleOptIn\Providers |
| 6 |
* @since 4.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Forge12\DoubleOptIn\Providers; |
| 10 |
|
| 11 |
use Forge12\DoubleOptIn\Container\Container; |
| 12 |
use Forge12\DoubleOptIn\Container\BootableProviderInterface; |
| 13 |
use Forge12\DoubleOptIn\EmailTemplates\EmailTemplatePostType; |
| 14 |
use Forge12\DoubleOptIn\EmailTemplates\EmailTemplateRepository; |
| 15 |
use Forge12\DoubleOptIn\EmailTemplates\EmailHtmlGenerator; |
| 16 |
use Forge12\DoubleOptIn\EmailTemplates\EmailTemplateIntegration; |
| 17 |
use Forge12\DoubleOptIn\EmailTemplates\BlockRegistry; |
| 18 |
|
| 19 |
if ( ! defined( 'ABSPATH' ) ) { |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Class EmailTemplateServiceProvider |
| 25 |
* |
| 26 |
* Registers email template services. |
| 27 |
*/ |
| 28 |
class EmailTemplateServiceProvider implements BootableProviderInterface { |
| 29 |
|
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function register( Container $container ): void { |
| 34 |
// Register Post Type |
| 35 |
$container->singleton( |
| 36 |
EmailTemplatePostType::class, |
| 37 |
function () { |
| 38 |
return new EmailTemplatePostType(); |
| 39 |
} |
| 40 |
); |
| 41 |
|
| 42 |
// Register Repository |
| 43 |
$container->singleton( |
| 44 |
EmailTemplateRepository::class, |
| 45 |
function () { |
| 46 |
return new EmailTemplateRepository(); |
| 47 |
} |
| 48 |
); |
| 49 |
|
| 50 |
// Register HTML Generator |
| 51 |
$container->singleton( |
| 52 |
EmailHtmlGenerator::class, |
| 53 |
function () { |
| 54 |
return new EmailHtmlGenerator(); |
| 55 |
} |
| 56 |
); |
| 57 |
|
| 58 |
// The template REST routes (editing) belong to the email editor |
| 59 |
// add-on since Core 5.8 / add-on 1.1.0. Core keeps what renders |
| 60 |
// saved templates at send time. |
| 61 |
|
| 62 |
// Register Block Registry |
| 63 |
$container->singleton( |
| 64 |
BlockRegistry::class, |
| 65 |
function () { |
| 66 |
return new BlockRegistry(); |
| 67 |
} |
| 68 |
); |
| 69 |
|
| 70 |
// Register Integration |
| 71 |
$container->singleton( |
| 72 |
EmailTemplateIntegration::class, |
| 73 |
function () { |
| 74 |
return new EmailTemplateIntegration(); |
| 75 |
} |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* {@inheritdoc} |
| 81 |
*/ |
| 82 |
public function boot( Container $container ): void { |
| 83 |
// Initialize Post Type — needed even on free sites so that |
| 84 |
// existing template posts in wp_posts continue to behave like |
| 85 |
// the registered post type (admin column, capabilities, etc.). |
| 86 |
$postType = $container->get( EmailTemplatePostType::class ); |
| 87 |
$postType->init(); |
| 88 |
|
| 89 |
// The template REST routes live in addon-email-editor (1.1.0+), |
| 90 |
// which registers them itself. Core ships no editing code. |
| 91 |
|
| 92 |
// Initialize Integration with CF7/Avada — used by the email |
| 93 |
// pipeline for templates referenced in form settings, so it |
| 94 |
// stays in Core (otherwise free users couldn't send templated |
| 95 |
// confirmation mails for templates created earlier or via the |
| 96 |
// legacy UI). |
| 97 |
$integration = $container->get( EmailTemplateIntegration::class ); |
| 98 |
$integration->init(); |
| 99 |
} |
| 100 |
} |
| 101 |
|