Remove the custom editor page
[MAILPOET-6090]
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
bc7bb56f90
commit
33e828f2ed
@@ -1,138 +0,0 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\AdminPages\Pages;
|
||||
|
||||
use MailPoet\API\JSON\API;
|
||||
use MailPoet\Config\Env;
|
||||
use MailPoet\Config\Installer;
|
||||
use MailPoet\Config\ServicesChecker;
|
||||
use MailPoet\EmailEditor\Engine\Settings_Controller;
|
||||
use MailPoet\EmailEditor\Engine\Theme_Controller;
|
||||
use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor as EditorInitController;
|
||||
use MailPoet\Newsletter\NewslettersRepository;
|
||||
use MailPoet\Settings\SettingsController as MailPoetSettings;
|
||||
use MailPoet\Util\CdnAssetUrl;
|
||||
use MailPoet\Util\License\Features\Subscribers as SubscribersFeature;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class EmailEditor {
|
||||
private WPFunctions $wp;
|
||||
|
||||
private Settings_Controller $settingsController;
|
||||
|
||||
private Theme_Controller $themeController;
|
||||
|
||||
private CdnAssetUrl $cdnAssetUrl;
|
||||
|
||||
private ServicesChecker $servicesChecker;
|
||||
|
||||
private SubscribersFeature $subscribersFeature;
|
||||
|
||||
private MailPoetSettings $mailpoetSettings;
|
||||
|
||||
private NewslettersRepository $newslettersRepository;
|
||||
|
||||
public function __construct(
|
||||
WPFunctions $wp,
|
||||
Settings_Controller $settingsController,
|
||||
CdnAssetUrl $cdnAssetUrl,
|
||||
ServicesChecker $servicesChecker,
|
||||
SubscribersFeature $subscribersFeature,
|
||||
Theme_Controller $themeController,
|
||||
MailPoetSettings $mailpoetSettings,
|
||||
NewslettersRepository $newslettersRepository
|
||||
) {
|
||||
$this->wp = $wp;
|
||||
$this->settingsController = $settingsController;
|
||||
$this->cdnAssetUrl = $cdnAssetUrl;
|
||||
$this->servicesChecker = $servicesChecker;
|
||||
$this->subscribersFeature = $subscribersFeature;
|
||||
$this->themeController = $themeController;
|
||||
$this->mailpoetSettings = $mailpoetSettings;
|
||||
$this->newslettersRepository = $newslettersRepository;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$postId = isset($_GET['postId']) ? intval($_GET['postId']) : 0;
|
||||
$post = $this->wp->getPost($postId);
|
||||
if (!$post instanceof \WP_Post || $post->post_type !== EditorInitController::MAILPOET_EMAIL_POST_TYPE) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
return;
|
||||
}
|
||||
|
||||
$assetsParams = require_once Env::$assetsPath . '/dist/js/email-editor/email_editor.asset.php';
|
||||
$this->wp->wpEnqueueScript(
|
||||
'mailpoet_email_editor',
|
||||
Env::$assetsUrl . '/dist/js/email-editor/email_editor.js',
|
||||
$assetsParams['dependencies'],
|
||||
$assetsParams['version'],
|
||||
true
|
||||
);
|
||||
$this->wp->wpEnqueueStyle(
|
||||
'mailpoet_email_editor',
|
||||
Env::$assetsUrl . '/dist/js/email-editor/email_editor.css',
|
||||
[],
|
||||
$assetsParams['version']
|
||||
);
|
||||
|
||||
$jsonAPIRoot = rtrim($this->wp->escUrlRaw(admin_url('admin-ajax.php')), '/');
|
||||
$token = $this->wp->wpCreateNonce('mailpoet_token');
|
||||
$apiVersion = API::CURRENT_VERSION;
|
||||
$currentUserEmail = $this->wp->wpGetCurrentUser()->user_email;
|
||||
$this->wp->wpLocalizeScript(
|
||||
'mailpoet_email_editor',
|
||||
'MailPoetEmailEditor',
|
||||
[
|
||||
'json_api_root' => esc_js($jsonAPIRoot),
|
||||
'api_token' => esc_js($token),
|
||||
'api_version' => esc_js($apiVersion),
|
||||
'cdn_url' => esc_js($this->cdnAssetUrl->generateCdnUrl("")),
|
||||
'is_premium_plugin_active' => (bool)$this->servicesChecker->isPremiumPluginActive(),
|
||||
'current_wp_user_email' => esc_js($currentUserEmail),
|
||||
'editor_settings' => $this->settingsController->get_settings(),
|
||||
'editor_theme' => $this->themeController->get_theme()->get_raw_data(),
|
||||
'urls' => [
|
||||
'listings' => admin_url('admin.php?page=mailpoet-newsletters'),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Renders additional script data that some components require e.g. PremiumModal. This is done here instead of using
|
||||
// PageRenderer since that introduces other dependencies we want to avoid. Used by getUpgradeInfo.
|
||||
// some of these values are used by the powered by mailpoet block: mailpoet/assets/js/src/mailpoet-custom-email-editor-blocks/powered-by-mailpoet/
|
||||
$installer = new Installer(Installer::PREMIUM_PLUGIN_SLUG);
|
||||
$inline_script_data = [
|
||||
'mailpoet_premium_plugin_installed' => Installer::isPluginInstalled(Installer::PREMIUM_PLUGIN_SLUG),
|
||||
'mailpoet_premium_plugin_active' => $this->servicesChecker->isPremiumPluginActive(),
|
||||
'mailpoet_premium_plugin_download_url' => $this->subscribersFeature->hasValidPremiumKey() ? $installer->generatePluginDownloadUrl() : null,
|
||||
'mailpoet_premium_plugin_activation_url' => $installer->generatePluginActivationUrl(Installer::PREMIUM_PLUGIN_PATH),
|
||||
'mailpoet_has_valid_api_key' => $this->subscribersFeature->hasValidApiKey(),
|
||||
'mailpoet_has_valid_premium_key' => $this->subscribersFeature->hasValidPremiumKey(),
|
||||
'mailpoet_has_premium_support' => $this->subscribersFeature->hasPremiumSupport(),
|
||||
'mailpoet_plugin_partial_key' => $this->servicesChecker->generatePartialApiKey(),
|
||||
'mailpoet_subscribers_count' => $this->subscribersFeature->getSubscribersCount(),
|
||||
'mailpoet_subscribers_limit' => $this->subscribersFeature->getSubscribersLimit(),
|
||||
'mailpoet_subscribers_limit_reached' => $this->subscribersFeature->check(),
|
||||
// settings needed for Satismeter tracking
|
||||
'mailpoet_3rd_party_libs_enabled' => $this->mailpoetSettings->get('3rd_party_libs.enabled') === '1',
|
||||
'mailpoet_display_nps_email_editor' => $this->newslettersRepository->getCountOfEmailsWithWPPost() > 1, // Poll should be displayed only if there are 2 and more emails
|
||||
'mailpoet_display_nps_poll' => true,
|
||||
'mailpoet_current_wp_user' => $this->wp->wpGetCurrentUser()->to_array(),
|
||||
'mailpoet_current_wp_user_firstname' => $this->wp->wpGetCurrentUser()->user_firstname,
|
||||
'mailpoet_cdn_url' => $this->cdnAssetUrl->generateCdnUrl(""),
|
||||
'mailpoet_site_url' => $this->wp->siteUrl(),
|
||||
];
|
||||
$this->wp->wpAddInlineScript('mailpoet_email_editor', implode('', array_map(function ($key) use ($inline_script_data) {
|
||||
return sprintf("var %s=%s;", $key, json_encode($inline_script_data[$key]));
|
||||
}, array_keys($inline_script_data))), 'before');
|
||||
|
||||
// Load CSS from Post Editor
|
||||
$this->wp->wpEnqueueStyle('wp-edit-post');
|
||||
// Load CSS for the format library - used for example in popover
|
||||
$this->wp->wpEnqueueStyle('wp-format-library');
|
||||
|
||||
// Enqueue media library scripts
|
||||
$this->wp->wpEnqueueMedia();
|
||||
|
||||
echo '<div id="mailpoet-email-editor" class="block-editor block-editor__container hide-if-no-js"></div>';
|
||||
}
|
||||
}
|
@@ -7,7 +7,6 @@ use MailPoet\AdminPages\Pages\AutomationAnalytics;
|
||||
use MailPoet\AdminPages\Pages\AutomationEditor;
|
||||
use MailPoet\AdminPages\Pages\AutomationTemplates;
|
||||
use MailPoet\AdminPages\Pages\DynamicSegments;
|
||||
use MailPoet\AdminPages\Pages\EmailEditor as EmailEditorPage;
|
||||
use MailPoet\AdminPages\Pages\ExperimentalFeatures;
|
||||
use MailPoet\AdminPages\Pages\FormEditor;
|
||||
use MailPoet\AdminPages\Pages\Forms;
|
||||
@@ -38,7 +37,6 @@ class Menu {
|
||||
const EMAILS_PAGE_SLUG = 'mailpoet-newsletters';
|
||||
const FORMS_PAGE_SLUG = 'mailpoet-forms';
|
||||
const EMAIL_EDITOR_PAGE_SLUG = 'mailpoet-newsletter-editor';
|
||||
const EMAIL_EDITOR_V2_PAGE_SLUG = 'mailpoet-email-editor';
|
||||
const FORM_EDITOR_PAGE_SLUG = 'mailpoet-form-editor';
|
||||
const HOMEPAGE_PAGE_SLUG = 'mailpoet-homepage';
|
||||
const FORM_TEMPLATES_PAGE_SLUG = 'mailpoet-form-editor-template-selection';
|
||||
@@ -263,27 +261,6 @@ class Menu {
|
||||
]
|
||||
);
|
||||
|
||||
// newsletter editor
|
||||
$emailEditorPage = $this->wp->addSubmenuPage(
|
||||
self::EMAILS_PAGE_SLUG,
|
||||
$this->setPageTitle(__('Email', 'mailpoet')),
|
||||
esc_html__('Email Editor', 'mailpoet'),
|
||||
AccessControl::PERMISSION_MANAGE_EMAILS,
|
||||
self::EMAIL_EDITOR_V2_PAGE_SLUG,
|
||||
[
|
||||
$this,
|
||||
'emailEditor',
|
||||
]
|
||||
);
|
||||
|
||||
// Add body class for email editor page
|
||||
// We need to mark the page as a block editor page so that some of the block editor styles are applied properly
|
||||
$this->wp->addAction('load-' . $emailEditorPage, function() {
|
||||
$this->wp->addFilter('admin_body_class', function ($classes) {
|
||||
return ltrim($classes . ' block-editor-page');
|
||||
});
|
||||
});
|
||||
|
||||
$this->registerAutomationMenu();
|
||||
|
||||
// Forms page
|
||||
@@ -654,10 +631,6 @@ class Menu {
|
||||
$this->container->get(NewsletterEditor::class)->render();
|
||||
}
|
||||
|
||||
public function emailEditor() {
|
||||
$this->container->get(EmailEditorPage::class)->render();
|
||||
}
|
||||
|
||||
public function import() {
|
||||
$this->container->get(SubscribersImport::class)->render();
|
||||
}
|
||||
|
@@ -37,7 +37,6 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\AutomationEditor::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\AutomationAnalytics::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\DynamicSegments::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\EmailEditor::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\ExperimentalFeatures::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\FormEditor::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\AdminPages\Pages\Forms::class)->setPublic(true);
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace MailPoet\EmailEditor\Integrations\MailPoet;
|
||||
|
||||
use MailPoet\Config\Menu;
|
||||
use MailPoet\Features\FeaturesController;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
@@ -63,15 +62,11 @@ class EmailEditor {
|
||||
if ($isEditorPage) {
|
||||
return $isEditorPage;
|
||||
}
|
||||
if ($this->wp->isAdmin()) {
|
||||
// Check on for post editor page
|
||||
if (isset($_GET['post']) && isset($_GET['action']) && $_GET['action'] === 'edit') {
|
||||
if ($this->wp->isAdmin() && isset($_GET['post']) && isset($_GET['action']) && $_GET['action'] === 'edit') {
|
||||
$post = $this->wp->getPost((int)$_GET['post']);
|
||||
return $post && $post->post_type === self::MAILPOET_EMAIL_POST_TYPE; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
}
|
||||
// Check for custom mailpoet email editor page
|
||||
return (isset($_GET['page']) && $_GET['page'] === Menu::EMAIL_EDITOR_V2_PAGE_SLUG);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -10,9 +10,7 @@ import {
|
||||
|
||||
export function getInitialState(): State {
|
||||
const searchParams = new URLSearchParams( window.location.search );
|
||||
const postId = parseInt( searchParams.get( 'post' ), 10 )
|
||||
? parseInt( searchParams.get( 'post' ), 10 )
|
||||
: parseInt( searchParams.get( 'postId' ), 10 );
|
||||
const postId = parseInt( searchParams.get( 'post' ), 10 );
|
||||
return {
|
||||
inserterSidebar: {
|
||||
isOpened: false,
|
||||
|
Reference in New Issue
Block a user