| 1 |
<?php |
| 2 |
|
| 3 |
namespace MailPoet\Config; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) exit; |
| 6 |
|
| 7 |
|
| 8 |
use MailPoet\AdminPages\Pages\Automation; |
| 9 |
use MailPoet\AdminPages\Pages\AutomationEditor; |
| 10 |
use MailPoet\AdminPages\Pages\AutomationTemplates; |
| 11 |
use MailPoet\AdminPages\Pages\ExperimentalFeatures; |
| 12 |
use MailPoet\AdminPages\Pages\FormEditor; |
| 13 |
use MailPoet\AdminPages\Pages\Forms; |
| 14 |
use MailPoet\AdminPages\Pages\Help; |
| 15 |
use MailPoet\AdminPages\Pages\Logs; |
| 16 |
use MailPoet\AdminPages\Pages\NewsletterEditor; |
| 17 |
use MailPoet\AdminPages\Pages\Newsletters; |
| 18 |
use MailPoet\AdminPages\Pages\Segments; |
| 19 |
use MailPoet\AdminPages\Pages\Settings; |
| 20 |
use MailPoet\AdminPages\Pages\Subscribers; |
| 21 |
use MailPoet\AdminPages\Pages\SubscribersExport; |
| 22 |
use MailPoet\AdminPages\Pages\SubscribersImport; |
| 23 |
use MailPoet\AdminPages\Pages\Upgrade; |
| 24 |
use MailPoet\AdminPages\Pages\WelcomeWizard; |
| 25 |
use MailPoet\AdminPages\Pages\WooCommerceSetup; |
| 26 |
use MailPoet\DI\ContainerWrapper; |
| 27 |
use MailPoet\Form\Util\CustomFonts; |
| 28 |
use MailPoet\Util\License\License; |
| 29 |
use MailPoet\WP\Functions as WPFunctions; |
| 30 |
|
| 31 |
class Menu { |
| 32 |
const MAIN_PAGE_SLUG = 'mailpoet-newsletters'; |
| 33 |
|
| 34 |
const ICON_BASE64_SVG = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNTIuMDIgMTU2LjQiPjx0aXRsZT5NYWlsUG9ldCBpY29uPC90aXRsZT48ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIj48ZyBpZD0iTGF5ZXJfMS0yIiBkYXRhLW5hbWU9IkxheWVyIDEiPjxwYXRoIGZpbGw9ImN1cnJlbnRDb2xvciIgZD0iTTM3LjcxLDg5LjFjMy41LDAsNS45LS44LDcuMi0yLjNhOCw4LDAsMCwwLDItNS40VjM1LjdsMTcsNDUuMWExMi42OCwxMi42OCwwLDAsMCwzLjcsNS40YzEuNiwxLjMsNCwyLDcuMiwyYTEyLjU0LDEyLjU0LDAsMCwwLDUuOS0xLjQsOC40MSw4LjQxLDAsMCwwLDMuOS01bDE4LjEtNTBWODFhOC41Myw4LjUzLDAsMCwwLDIuMSw2LjFjMS40LDEuNCwzLjcsMi4yLDYuOSwyLjIsMy41LDAsNS45LS44LDcuMi0yLjNhOCw4LDAsMCwwLDItNS40VjguN2E3LjQ4LDcuNDgsMCwwLDAtMy4zLTYuNmMtMi4xLTEuNC01LTIuMS04LjYtMi4xYTE5LjMsMTkuMywwLDAsMC05LjQsMiwxMS42MywxMS42MywwLDAsMC01LjEsNi44TDc0LjkxLDY3LjEsNTQuNDEsOC40YTEyLjQsMTIuNCwwLDAsMC00LjUtNi4yYy0yLjEtMS41LTUtMi4yLTguOC0yLjJhMTYuNTEsMTYuNTEsMCwwLDAtOC45LDIuMWMtMi4zLDEuNS0zLjUsMy45LTMuNSw3LjJWODAuOGMwLDIuOC43LDQuOCwyLDYuMkMzMi4yMSw4OC40LDM0LjQxLDg5LjEsMzcuNzEsODkuMVoiLz48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0xNDksMTE2LjZsLTIuNC0xLjlhNy40LDcuNCwwLDAsMC05LjQuMywxOS42NSwxOS42NSwwLDAsMS0xMi41LDQuNmgtMjEuNEEzNy4wOCwzNy4wOCwwLDAsMCw3NywxMzAuNWwtMS4xLDEuMi0xLjEtMS4xYTM3LjI1LDM3LjI1LDAsMCwwLTI2LjMtMTAuOUgyN2ExOS41OSwxOS41OSwwLDAsMS0xMi40LTQuNiw3LjI4LDcuMjgsMCwwLDAtOS40LS4zbC0yLjQsMS45QTcuNDMsNy40MywwLDAsMCwwLDEyMi4yYTcuMTQsNy4xNCwwLDAsMCwyLjQsNS43QTM3LjI4LDM3LjI4LDAsMCwwLDI3LDEzNy40aDIxLjZhMTkuNTksMTkuNTksMCwwLDEsMTguOSwxNC40di4yYy4xLjcsMS4yLDQuNCw4LjUsNC40czguNC0zLjcsOC41LTQuNHYtLjJhMTkuNTksMTkuNTksMCwwLDEsMTguOS0xNC40SDEyNWEzNy4yOCwzNy4yOCwwLDAsMCwyNC42LTkuNSw3LjQyLDcuNDIsMCwwLDAsMi40LTUuN0E3Ljg2LDcuODYsMCwwLDAsMTQ5LDExNi42WiIvPjwvZz48L2c+PC9zdmc+'; |
| 35 |
|
| 36 |
public $mpApiKeyValid; |
| 37 |
public $premiumKeyValid; |
| 38 |
|
| 39 |
/** @var AccessControl */ |
| 40 |
private $accessControl; |
| 41 |
|
| 42 |
/** @var WPFunctions */ |
| 43 |
private $wp; |
| 44 |
|
| 45 |
/** @var ServicesChecker */ |
| 46 |
private $servicesChecker; |
| 47 |
|
| 48 |
/** @var ContainerWrapper */ |
| 49 |
private $container; |
| 50 |
|
| 51 |
/** @var Router */ |
| 52 |
private $router; |
| 53 |
|
| 54 |
/** @var CustomFonts */ |
| 55 |
private $customFonts; |
| 56 |
|
| 57 |
public function __construct( |
| 58 |
AccessControl $accessControl, |
| 59 |
WPFunctions $wp, |
| 60 |
ServicesChecker $servicesChecker, |
| 61 |
ContainerWrapper $container, |
| 62 |
Router $router, |
| 63 |
CustomFonts $customFonts |
| 64 |
) { |
| 65 |
$this->accessControl = $accessControl; |
| 66 |
$this->wp = $wp; |
| 67 |
$this->servicesChecker = $servicesChecker; |
| 68 |
$this->container = $container; |
| 69 |
$this->router = $router; |
| 70 |
$this->customFonts = $customFonts; |
| 71 |
} |
| 72 |
|
| 73 |
public function init() { |
| 74 |
$this->checkPremiumKey(); |
| 75 |
|
| 76 |
$this->wp->addAction( |
| 77 |
'admin_menu', |
| 78 |
[ |
| 79 |
$this, |
| 80 |
'setup', |
| 81 |
] |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
public function setup() { |
| 86 |
if (!$this->accessControl->validatePermission(AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN)) return; |
| 87 |
|
| 88 |
$this->router->checkRedirects(); |
| 89 |
|
| 90 |
$this->registerMailPoetMenu(); |
| 91 |
|
| 92 |
// @ToDo Remove Beta once Automation is no longer beta. |
| 93 |
$this->wp->addAction('admin_head', function () { |
| 94 |
echo '<style> |
| 95 |
#adminmenu .toplevel_page_mailpoet-newsletters a[href="admin.php?page=mailpoet-automation"] { |
| 96 |
white-space: nowrap; |
| 97 |
} |
| 98 |
.mailpoet-beta-badge { |
| 99 |
text-transform: uppercase; |
| 100 |
font-size: 9px; |
| 101 |
position: relative; |
| 102 |
top: -5px; |
| 103 |
color: #ffab66; |
| 104 |
} |
| 105 |
</style>'; |
| 106 |
}); |
| 107 |
|
| 108 |
if (!self::isOnMailPoetAdminPage()) { |
| 109 |
return; |
| 110 |
} |
| 111 |
$this->wp->doAction('mailpoet_conflict_resolver_styles'); |
| 112 |
$this->wp->doAction('mailpoet_conflict_resolver_scripts'); |
| 113 |
|
| 114 |
if ( |
| 115 |
!isset($_REQUEST['page']) |
| 116 |
|| sanitize_text_field(wp_unslash($_REQUEST['page'])) !== 'mailpoet-newsletter-editor' |
| 117 |
) { |
| 118 |
return; |
| 119 |
} |
| 120 |
// Disable WP emojis to not interfere with the newsletter editor emoji handling |
| 121 |
$this->disableWPEmojis(); |
| 122 |
if (!$this->customFonts->displayCustomFonts()) { |
| 123 |
return; |
| 124 |
} |
| 125 |
$this->wp->addAction('admin_head', function () { |
| 126 |
echo '<link href="https://fonts.googleapis.com/css?family=' |
| 127 |
. 'Arvo:400,400i,700,700i' |
| 128 |
. '|Lato:400,400i,700,700i' |
| 129 |
. '|Lora:400,400i,700,700i' |
| 130 |
. '|Merriweather:400,400i,700,700i' |
| 131 |
. '|Merriweather+Sans:400,400i,700,700i' |
| 132 |
. '|Noticia+Text:400,400i,700,700i' |
| 133 |
. '|Open+Sans:400,400i,700,700i' |
| 134 |
. '|Playfair+Display:400,400i,700,700i' |
| 135 |
. '|Roboto:400,400i,700,700i' |
| 136 |
. '|Source+Sans+Pro:400,400i,700,700i' |
| 137 |
. '|Oswald:400,400i,700,700i' |
| 138 |
. '|Raleway:400,400i,700,700i' |
| 139 |
. '|Permanent+Marker:400,400i,700,700i' |
| 140 |
. '|Pacifico:400,400i,700,700i' |
| 141 |
. '" rel="stylesheet">'; |
| 142 |
}); |
| 143 |
} |
| 144 |
|
| 145 |
private function registerMailPoetMenu() { |
| 146 |
|
| 147 |
// Main page |
| 148 |
$this->wp->addMenuPage( |
| 149 |
'MailPoet', |
| 150 |
'MailPoet', |
| 151 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 152 |
self::MAIN_PAGE_SLUG, |
| 153 |
null, |
| 154 |
self::ICON_BASE64_SVG, |
| 155 |
30 |
| 156 |
); |
| 157 |
|
| 158 |
// Emails page |
| 159 |
$newslettersPage = $this->wp->addSubmenuPage( |
| 160 |
self::MAIN_PAGE_SLUG, |
| 161 |
$this->setPageTitle(__('Emails', 'mailpoet')), |
| 162 |
esc_html__('Emails', 'mailpoet'), |
| 163 |
AccessControl::PERMISSION_MANAGE_EMAILS, |
| 164 |
self::MAIN_PAGE_SLUG, |
| 165 |
[ |
| 166 |
$this, |
| 167 |
'newsletters', |
| 168 |
] |
| 169 |
); |
| 170 |
|
| 171 |
// add limit per page to screen options |
| 172 |
$this->wp->addAction('load-' . $newslettersPage, function() { |
| 173 |
$this->wp->addScreenOption('per_page', [ |
| 174 |
'label' => _x( |
| 175 |
'Number of newsletters per page', |
| 176 |
'newsletters per page (screen options)', |
| 177 |
'mailpoet' |
| 178 |
), |
| 179 |
'option' => 'mailpoet_newsletters_per_page', |
| 180 |
]); |
| 181 |
}); |
| 182 |
|
| 183 |
// newsletter editor |
| 184 |
$this->wp->addSubmenuPage( |
| 185 |
true, |
| 186 |
$this->setPageTitle(__('Newsletter', 'mailpoet')), |
| 187 |
esc_html__('Newsletter Editor', 'mailpoet'), |
| 188 |
AccessControl::PERMISSION_MANAGE_EMAILS, |
| 189 |
'mailpoet-newsletter-editor', |
| 190 |
[ |
| 191 |
$this, |
| 192 |
'newletterEditor', |
| 193 |
] |
| 194 |
); |
| 195 |
|
| 196 |
$this->registerAutomationMenu(); |
| 197 |
|
| 198 |
// Forms page |
| 199 |
$formsPage = $this->wp->addSubmenuPage( |
| 200 |
self::MAIN_PAGE_SLUG, |
| 201 |
$this->setPageTitle(__('Forms', 'mailpoet')), |
| 202 |
esc_html__('Forms', 'mailpoet'), |
| 203 |
AccessControl::PERMISSION_MANAGE_FORMS, |
| 204 |
'mailpoet-forms', |
| 205 |
[ |
| 206 |
$this, |
| 207 |
'forms', |
| 208 |
] |
| 209 |
); |
| 210 |
|
| 211 |
// add limit per page to screen options |
| 212 |
$this->wp->addAction('load-' . $formsPage, function() { |
| 213 |
$this->wp->addScreenOption('per_page', [ |
| 214 |
'label' => _x( |
| 215 |
'Number of forms per page', |
| 216 |
'forms per page (screen options)', |
| 217 |
'mailpoet' |
| 218 |
), |
| 219 |
'option' => 'mailpoet_forms_per_page', |
| 220 |
]); |
| 221 |
}); |
| 222 |
|
| 223 |
// form editor |
| 224 |
$formEditorPage = $this->wp->addSubmenuPage( |
| 225 |
true, |
| 226 |
$this->setPageTitle(__('Form Editor', 'mailpoet')), |
| 227 |
esc_html__('Form Editor', 'mailpoet'), |
| 228 |
AccessControl::PERMISSION_MANAGE_FORMS, |
| 229 |
'mailpoet-form-editor', |
| 230 |
[ |
| 231 |
$this, |
| 232 |
'formEditor', |
| 233 |
] |
| 234 |
); |
| 235 |
|
| 236 |
// add body class for form editor page |
| 237 |
$this->wp->addAction('load-' . $formEditorPage, function() { |
| 238 |
$this->wp->addFilter('admin_body_class', function ($classes) { |
| 239 |
return ltrim($classes . ' block-editor-page'); |
| 240 |
}); |
| 241 |
}); |
| 242 |
|
| 243 |
// form editor templates |
| 244 |
$formTemplateSelectionEditorPage = $this->wp->addSubmenuPage( |
| 245 |
true, |
| 246 |
$this->setPageTitle(__('Select Form Template', 'mailpoet')), |
| 247 |
esc_html__('Select Form Template', 'mailpoet'), |
| 248 |
AccessControl::PERMISSION_MANAGE_FORMS, |
| 249 |
'mailpoet-form-editor-template-selection', |
| 250 |
[ |
| 251 |
$this, |
| 252 |
'formEditorTemplateSelection', |
| 253 |
] |
| 254 |
); |
| 255 |
|
| 256 |
// add body class for form editor page |
| 257 |
$this->wp->addAction('load-' . $formTemplateSelectionEditorPage, function() { |
| 258 |
$this->wp->addFilter('admin_body_class', function ($classes) { |
| 259 |
return ltrim($classes . ' block-editor-page'); |
| 260 |
}); |
| 261 |
}); |
| 262 |
|
| 263 |
|
| 264 |
// Subscribers page |
| 265 |
$subscribersPage = $this->wp->addSubmenuPage( |
| 266 |
self::MAIN_PAGE_SLUG, |
| 267 |
$this->setPageTitle(__('Subscribers', 'mailpoet')), |
| 268 |
esc_html__('Subscribers', 'mailpoet'), |
| 269 |
AccessControl::PERMISSION_MANAGE_SUBSCRIBERS, |
| 270 |
'mailpoet-subscribers', |
| 271 |
[ |
| 272 |
$this, |
| 273 |
'subscribers', |
| 274 |
] |
| 275 |
); |
| 276 |
|
| 277 |
// add limit per page to screen options |
| 278 |
$this->wp->addAction('load-' . $subscribersPage, function() { |
| 279 |
$this->wp->addScreenOption('per_page', [ |
| 280 |
'label' => _x( |
| 281 |
'Number of subscribers per page', |
| 282 |
'subscribers per page (screen options)', |
| 283 |
'mailpoet' |
| 284 |
), |
| 285 |
'option' => 'mailpoet_subscribers_per_page', |
| 286 |
]); |
| 287 |
}); |
| 288 |
|
| 289 |
// import |
| 290 |
$this->wp->addSubmenuPage( |
| 291 |
'admin.php?page=mailpoet-subscribers', |
| 292 |
$this->setPageTitle(__('Import', 'mailpoet')), |
| 293 |
esc_html__('Import', 'mailpoet'), |
| 294 |
AccessControl::PERMISSION_MANAGE_SUBSCRIBERS, |
| 295 |
'mailpoet-import', |
| 296 |
[ |
| 297 |
$this, |
| 298 |
'import', |
| 299 |
] |
| 300 |
); |
| 301 |
|
| 302 |
// export |
| 303 |
$this->wp->addSubmenuPage( |
| 304 |
true, |
| 305 |
$this->setPageTitle(__('Export', 'mailpoet')), |
| 306 |
esc_html__('Export', 'mailpoet'), |
| 307 |
AccessControl::PERMISSION_MANAGE_SUBSCRIBERS, |
| 308 |
'mailpoet-export', |
| 309 |
[ |
| 310 |
$this, |
| 311 |
'export', |
| 312 |
] |
| 313 |
); |
| 314 |
|
| 315 |
// Segments page |
| 316 |
$segmentsPage = $this->wp->addSubmenuPage( |
| 317 |
self::MAIN_PAGE_SLUG, |
| 318 |
$this->setPageTitle(__('Lists', 'mailpoet')), |
| 319 |
esc_html__('Lists', 'mailpoet'), |
| 320 |
AccessControl::PERMISSION_MANAGE_SEGMENTS, |
| 321 |
'mailpoet-segments', |
| 322 |
[ |
| 323 |
$this, |
| 324 |
'segments', |
| 325 |
] |
| 326 |
); |
| 327 |
|
| 328 |
// add limit per page to screen options |
| 329 |
$this->wp->addAction('load-' . $segmentsPage, function() { |
| 330 |
$this->wp->addScreenOption('per_page', [ |
| 331 |
'label' => _x( |
| 332 |
'Number of segments per page', |
| 333 |
'segments per page (screen options)', |
| 334 |
'mailpoet' |
| 335 |
), |
| 336 |
'option' => 'mailpoet_segments_per_page', |
| 337 |
]); |
| 338 |
}); |
| 339 |
|
| 340 |
// Settings page |
| 341 |
$this->wp->addSubmenuPage( |
| 342 |
self::MAIN_PAGE_SLUG, |
| 343 |
$this->setPageTitle(__('Settings', 'mailpoet')), |
| 344 |
esc_html__('Settings', 'mailpoet'), |
| 345 |
AccessControl::PERMISSION_MANAGE_SETTINGS, |
| 346 |
'mailpoet-settings', |
| 347 |
[ |
| 348 |
$this, |
| 349 |
'settings', |
| 350 |
] |
| 351 |
); |
| 352 |
|
| 353 |
// Help page |
| 354 |
$this->wp->addSubmenuPage( |
| 355 |
self::MAIN_PAGE_SLUG, |
| 356 |
$this->setPageTitle(__('Help', 'mailpoet')), |
| 357 |
esc_html__('Help', 'mailpoet'), |
| 358 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 359 |
'mailpoet-help', |
| 360 |
[ |
| 361 |
$this, |
| 362 |
'help', |
| 363 |
] |
| 364 |
); |
| 365 |
|
| 366 |
// Upgrade page |
| 367 |
// Only show this page in menu if the Premium plugin is not activated |
| 368 |
$this->wp->addSubmenuPage( |
| 369 |
License::getLicense() ? true : self::MAIN_PAGE_SLUG, |
| 370 |
$this->setPageTitle(__('Upgrade', 'mailpoet')), |
| 371 |
esc_html__('Upgrade', 'mailpoet'), |
| 372 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 373 |
'mailpoet-upgrade', |
| 374 |
[ |
| 375 |
$this, |
| 376 |
'upgrade', |
| 377 |
] |
| 378 |
); |
| 379 |
|
| 380 |
// Welcome wizard page |
| 381 |
$this->wp->addSubmenuPage( |
| 382 |
true, |
| 383 |
$this->setPageTitle(__('Welcome Wizard', 'mailpoet')), |
| 384 |
esc_html__('Welcome Wizard', 'mailpoet'), |
| 385 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 386 |
'mailpoet-welcome-wizard', |
| 387 |
[ |
| 388 |
$this, |
| 389 |
'welcomeWizard', |
| 390 |
] |
| 391 |
); |
| 392 |
|
| 393 |
// WooCommerce Setup |
| 394 |
$this->wp->addSubmenuPage( |
| 395 |
true, |
| 396 |
$this->setPageTitle(__('WooCommerce Setup', 'mailpoet')), |
| 397 |
esc_html__('WooCommerce Setup', 'mailpoet'), |
| 398 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 399 |
'mailpoet-woocommerce-setup', |
| 400 |
[ |
| 401 |
$this, |
| 402 |
'wooCommerceSetup', |
| 403 |
] |
| 404 |
); |
| 405 |
|
| 406 |
// Experimental page |
| 407 |
$this->wp->addSubmenuPage( |
| 408 |
true, |
| 409 |
$this->setPageTitle(__('Experimental Features', 'mailpoet')), |
| 410 |
'', |
| 411 |
AccessControl::PERMISSION_MANAGE_FEATURES, |
| 412 |
'mailpoet-experimental', |
| 413 |
[$this, 'experimentalFeatures'] |
| 414 |
); |
| 415 |
|
| 416 |
// display loggs page |
| 417 |
$this->wp->addSubmenuPage( |
| 418 |
true, |
| 419 |
$this->setPageTitle(__('Logs', 'mailpoet')), |
| 420 |
'', |
| 421 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 422 |
'mailpoet-logs', |
| 423 |
[$this, 'logs'] |
| 424 |
); |
| 425 |
|
| 426 |
} |
| 427 |
|
| 428 |
private function registerAutomationMenu() { |
| 429 |
$automationPage = $this->wp->addSubmenuPage( |
| 430 |
self::MAIN_PAGE_SLUG, |
| 431 |
$this->setPageTitle(__('Automations', 'mailpoet')), |
| 432 |
// @ToDo Remove Beta once Automation is no longer beta. |
| 433 |
'<span>' . esc_html__('Automations', 'mailpoet') . '</span><span class="mailpoet-beta-badge">Beta</span>', |
| 434 |
AccessControl::PERMISSION_MANAGE_EMAILS, |
| 435 |
'mailpoet-automation', |
| 436 |
[$this, 'automation'] |
| 437 |
); |
| 438 |
|
| 439 |
// Automation editor |
| 440 |
$automationEditorPage = $this->wp->addSubmenuPage( |
| 441 |
true, |
| 442 |
$this->setPageTitle(__('Automation Editor', 'mailpoet')), |
| 443 |
esc_html__('Automation Editor', 'mailpoet'), |
| 444 |
AccessControl::PERMISSION_MANAGE_AUTOMATIONS, |
| 445 |
'mailpoet-automation-editor', |
| 446 |
[$this, 'automationEditor'] |
| 447 |
); |
| 448 |
|
| 449 |
// Automation templates |
| 450 |
$this->wp->addSubmenuPage( |
| 451 |
true, |
| 452 |
$this->setPageTitle(__('Automation Templates', 'mailpoet')), |
| 453 |
esc_html__('Automation Templates', 'mailpoet'), |
| 454 |
AccessControl::PERMISSION_MANAGE_AUTOMATIONS, |
| 455 |
'mailpoet-automation-templates', |
| 456 |
[$this, 'automationTemplates'] |
| 457 |
); |
| 458 |
|
| 459 |
// add body class for automation editor page |
| 460 |
$this->wp->addAction('load-' . $automationPage, function() { |
| 461 |
$this->wp->addFilter('admin_body_class', function ($classes) { |
| 462 |
return ltrim($classes . ' mailpoet-automation-is-onboarding'); |
| 463 |
}); |
| 464 |
}); |
| 465 |
$this->wp->addAction('load-' . $automationEditorPage, function() { |
| 466 |
$this->wp->addFilter('admin_body_class', function ($classes) { |
| 467 |
return ltrim($classes . ' site-editor-php'); |
| 468 |
}); |
| 469 |
}); |
| 470 |
} |
| 471 |
|
| 472 |
public function disableWPEmojis() { |
| 473 |
$this->wp->removeAction('admin_print_scripts', 'print_emoji_detection_script'); |
| 474 |
$this->wp->removeAction('admin_print_styles', 'print_emoji_styles'); |
| 475 |
} |
| 476 |
|
| 477 |
public function welcomeWizard() { |
| 478 |
$this->container->get(WelcomeWizard::class)->render(); |
| 479 |
} |
| 480 |
|
| 481 |
public function wooCommerceSetup() { |
| 482 |
$this->container->get(WooCommerceSetup::class)->render(); |
| 483 |
} |
| 484 |
|
| 485 |
public function upgrade() { |
| 486 |
$this->container->get(Upgrade::class)->render(); |
| 487 |
} |
| 488 |
|
| 489 |
public function settings() { |
| 490 |
$this->container->get(Settings::class)->render(); |
| 491 |
} |
| 492 |
|
| 493 |
public function help() { |
| 494 |
$this->container->get(Help::class)->render(); |
| 495 |
} |
| 496 |
|
| 497 |
public function automation() { |
| 498 |
$this->container->get(Automation::class)->render(); |
| 499 |
} |
| 500 |
|
| 501 |
public function automationTemplates() { |
| 502 |
$this->container->get(AutomationTemplates::class)->render(); |
| 503 |
} |
| 504 |
|
| 505 |
public function automationEditor() { |
| 506 |
$this->container->get(AutomationEditor::class)->render(); |
| 507 |
} |
| 508 |
|
| 509 |
public function experimentalFeatures() { |
| 510 |
$this->container->get(ExperimentalFeatures::class)->render(); |
| 511 |
} |
| 512 |
|
| 513 |
public function logs() { |
| 514 |
$this->container->get(Logs::class)->render(); |
| 515 |
} |
| 516 |
|
| 517 |
public function subscribers() { |
| 518 |
$this->container->get(Subscribers::class)->render(); |
| 519 |
} |
| 520 |
|
| 521 |
public function segments() { |
| 522 |
$this->container->get(Segments::class)->render(); |
| 523 |
} |
| 524 |
|
| 525 |
public function forms() { |
| 526 |
$this->container->get(Forms::class)->render(); |
| 527 |
} |
| 528 |
|
| 529 |
public function newsletters() { |
| 530 |
$this->container->get(Newsletters::class)->render(); |
| 531 |
} |
| 532 |
|
| 533 |
public function newletterEditor() { |
| 534 |
$this->container->get(NewsletterEditor::class)->render(); |
| 535 |
} |
| 536 |
|
| 537 |
public function import() { |
| 538 |
$this->container->get(SubscribersImport::class)->render(); |
| 539 |
} |
| 540 |
|
| 541 |
public function export() { |
| 542 |
$this->container->get(SubscribersExport::class)->render(); |
| 543 |
} |
| 544 |
|
| 545 |
public function formEditor() { |
| 546 |
$this->container->get(FormEditor::class)->render(); |
| 547 |
} |
| 548 |
|
| 549 |
public function formEditorTemplateSelection() { |
| 550 |
$this->container->get(FormEditor::class)->renderTemplateSelection(); |
| 551 |
} |
| 552 |
|
| 553 |
public function setPageTitle($title) { |
| 554 |
return sprintf( |
| 555 |
'%s - %s', |
| 556 |
__('MailPoet', 'mailpoet'), |
| 557 |
$title |
| 558 |
); |
| 559 |
} |
| 560 |
|
| 561 |
public static function isOnMailPoetAutomationPage(): bool { |
| 562 |
$screenId = isset($_REQUEST['page']) ? sanitize_text_field(wp_unslash($_REQUEST['page'])) : ''; |
| 563 |
$automationPages = [ |
| 564 |
'mailpoet-automation', |
| 565 |
'mailpoet-automation-templates', |
| 566 |
'mailpoet-automation-editor', |
| 567 |
]; |
| 568 |
return in_array( |
| 569 |
$screenId, |
| 570 |
$automationPages, |
| 571 |
true |
| 572 |
); |
| 573 |
} |
| 574 |
|
| 575 |
public static function isOnMailPoetAdminPage(array $exclude = null, $screenId = null) { |
| 576 |
if (is_null($screenId)) { |
| 577 |
if (empty($_REQUEST['page'])) { |
| 578 |
return false; |
| 579 |
} |
| 580 |
$screenId = sanitize_text_field(wp_unslash($_REQUEST['page'])); |
| 581 |
} |
| 582 |
if (!empty($exclude)) { |
| 583 |
foreach ($exclude as $slug) { |
| 584 |
if (stripos($screenId, $slug) !== false) { |
| 585 |
return false; |
| 586 |
} |
| 587 |
} |
| 588 |
} |
| 589 |
return (stripos($screenId, 'mailpoet-') !== false); |
| 590 |
} |
| 591 |
|
| 592 |
/** |
| 593 |
* This error page is used when the initialization is failed |
| 594 |
* to display admin notices only |
| 595 |
*/ |
| 596 |
public static function addErrorPage(AccessControl $accessControl) { |
| 597 |
if (!self::isOnMailPoetAdminPage() || !isset($_REQUEST['page'])) { |
| 598 |
return false; |
| 599 |
} |
| 600 |
|
| 601 |
$page = sanitize_text_field(wp_unslash($_REQUEST['page'])); |
| 602 |
// Check if page already exists |
| 603 |
if ( |
| 604 |
get_plugin_page_hook($page, '') |
| 605 |
|| WPFunctions::get()->getPluginPageHook($page, self::MAIN_PAGE_SLUG) |
| 606 |
) { |
| 607 |
return false; |
| 608 |
} |
| 609 |
WPFunctions::get()->addSubmenuPage( |
| 610 |
true, |
| 611 |
'MailPoet', |
| 612 |
'MailPoet', |
| 613 |
AccessControl::PERMISSION_ACCESS_PLUGIN_ADMIN, |
| 614 |
$page, |
| 615 |
[ |
| 616 |
__CLASS__, |
| 617 |
'errorPageCallback', |
| 618 |
] |
| 619 |
); |
| 620 |
} |
| 621 |
|
| 622 |
public static function errorPageCallback() { |
| 623 |
// Used for displaying admin notices only |
| 624 |
} |
| 625 |
|
| 626 |
public function checkPremiumKey(ServicesChecker $checker = null) { |
| 627 |
$showNotices = isset($_SERVER['SCRIPT_NAME']) |
| 628 |
&& stripos(sanitize_text_field(wp_unslash($_SERVER['SCRIPT_NAME'])), 'plugins.php') !== false; |
| 629 |
$checker = $checker ?: $this->servicesChecker; |
| 630 |
$this->premiumKeyValid = $checker->isPremiumKeyValid($showNotices); |
| 631 |
} |
| 632 |
} |
| 633 |
|