Files
piratepoet/mailpoet/lib/EmailEditor/Integrations/MailPoet/EmailEditor.php
Rostislav Wolny b35e0af691 Remove old code that was handling creating emails for the new editor
The code is no longer needed because the new emails are created via API.
[MAILPOET-5810]
2024-01-14 19:43:26 +05:00

60 lines
1.7 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\EmailEditor\Integrations\MailPoet;
use MailPoet\Features\FeaturesController;
use MailPoet\WP\Functions as WPFunctions;
class EmailEditor {
const MAILPOET_EMAIL_POST_TYPE = 'mailpoet_email';
/** @var WPFunctions */
private $wp;
/** @var FeaturesController */
private $featuresController;
/** @var EmailApiController */
private $emailApiController;
public function __construct(
WPFunctions $wp,
FeaturesController $featuresController,
EmailApiController $emailApiController
) {
$this->wp = $wp;
$this->featuresController = $featuresController;
$this->emailApiController = $emailApiController;
}
public function initialize(): void {
if (!$this->featuresController->isSupported(FeaturesController::GUTENBERG_EMAIL_EDITOR)) {
return;
}
$this->wp->addFilter('mailpoet_email_editor_post_types', [$this, 'addEmailPostType']);
$this->extendEmailPostApi();
}
public function addEmailPostType(array $postTypes): array {
$postTypes[] = [
'name' => self::MAILPOET_EMAIL_POST_TYPE,
'args' => [
'labels' => [
'name' => __('Emails', 'mailpoet'),
'singular_name' => __('Email', 'mailpoet'),
],
'rewrite' => ['slug' => self::MAILPOET_EMAIL_POST_TYPE],
],
];
return $postTypes;
}
public function extendEmailPostApi() {
$this->wp->registerRestField(self::MAILPOET_EMAIL_POST_TYPE, 'mailpoet_data', [
'get_callback' => [$this->emailApiController, 'getEmailData'],
'update_callback' => [$this->emailApiController, 'saveEmailData'],
'schema' => $this->emailApiController->getEmailDataSchema(),
]);
}
}