<?php namespace MailPoet\Config; if (!defined('ABSPATH')) exit; use MailPoet\Settings\SettingsController; use MailPoet\Util\Url; use MailPoet\WooCommerce\Helper; use MailPoet\WP\Functions as WPFunctions; class Changelog { /** @var WPFunctions */ private $wp; /** @var SettingsController */ private $settings; /** @var Helper */ private $wooCommerceHelper; /** @var Url */ private $urlHelper; /** @var MP2Migrator */ private $mp2Migrator; public function __construct( SettingsController $settings, WPFunctions $wp, Helper $wooCommerceHelper, Url $urlHelper, MP2Migrator $mp2Migrator ) { $this->wooCommerceHelper = $wooCommerceHelper; $this->settings = $settings; $this->wp = $wp; $this->urlHelper = $urlHelper; $this->mp2Migrator = $mp2Migrator; } public function init() { $doingAjax = (bool)(defined('DOING_AJAX') && DOING_AJAX); // don't run any check when it's an ajax request if ($doingAjax) { return; } // don't run any check when we're not on our pages if ( !(isset($_GET['page'])) or (isset($_GET['page']) && strpos($_GET['page'], 'mailpoet') !== 0) ) { return; } WPFunctions::get()->addAction( 'admin_init', [$this, 'check'] ); } public function check() { $version = $this->settings->get('version'); $this->checkMp2Migration($version); if ($version === null) { $this->setupNewInstallation(); $this->checkWelcomeWizard(); } $this->checkWooCommerceListImportPage(); $this->checkRevenueTrackingPermissionPage(); } private function checkMp2Migration($version) { if (!in_array($_GET['page'], ['mailpoet-migration', 'mailpoet-settings']) && $this->mp2Migrator->isMigrationStartedAndNotCompleted()) { // Force the redirection if the migration has started but is not completed return $this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration')); } if ($version === null && $this->mp2Migrator->isMigrationNeeded()) { $this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-migration')); } } private function setupNewInstallation() { $this->settings->set('show_congratulate_after_first_newsletter', true); } private function checkWelcomeWizard() { $skipWizard = $this->wp->applyFilters('mailpoet_skip_welcome_wizard', false); if (!$skipWizard) { $this->terminateWithRedirect($this->wp->adminUrl('admin.php?page=mailpoet-welcome-wizard')); } } private function checkWooCommerceListImportPage() { if ($this->wp->applyFilters('mailpoet_skip_woocommerce_import_page', false)) { return; } if ( !in_array($_GET['page'], ['mailpoet-woocommerce-setup', 'mailpoet-welcome-wizard', 'mailpoet-migration']) && !$this->settings->get('woocommerce_import_screen_displayed') && $this->wooCommerceHelper->isWooCommerceActive() && $this->wooCommerceHelper->getOrdersCountCreatedBefore($this->settings->get('installed_at')) > 0 && $this->wp->currentUserCan('administrator') ) { $this->urlHelper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-setup')); } } private function checkRevenueTrackingPermissionPage() { if ( !in_array($_GET['page'], ['mailpoet-woocommerce-setup', 'mailpoet-welcome-wizard', 'mailpoet-migration']) && ($this->settings->get('woocommerce.accept_cookie_revenue_tracking.set') === null) && $this->settings->get('tracking.enabled') && $this->wooCommerceHelper->isWooCommerceActive() && $this->wp->currentUserCan('administrator') ) { $this->urlHelper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-setup')); } } private function terminateWithRedirect($redirectUrl) { // save version number $this->settings->set('version', Env::$version); $this->urlHelper->redirectWithReferer($redirectUrl); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
PopulatorData | Folder | 0700 |
|
|
AccessControl.php | File | 3.23 KB | 0644 |
|
Activator.php | File | 2.22 KB | 0644 |
|
AssetsLoader.php | File | 801 B | 0644 |
|
Capabilities.php | File | 2.8 KB | 0644 |
|
Changelog.php | File | 3.9 KB | 0644 |
|
Database.php | File | 2.78 KB | 0644 |
|
DatabaseInitializer.php | File | 601 B | 0644 |
|
DeferredAdminNotices.php | File | 1.07 KB | 0644 |
|
Env.php | File | 3.93 KB | 0644 |
|
Hooks.php | File | 10.32 KB | 0644 |
|
HooksWooCommerce.php | File | 3.97 KB | 0644 |
|
Initializer.php | File | 9.92 KB | 0644 |
|
Installer.php | File | 2.69 KB | 0644 |
|
Localizer.php | File | 1.15 KB | 0644 |
|
MP2Migrator.php | File | 35.34 KB | 0644 |
|
Menu.php | File | 14.04 KB | 0644 |
|
Migrator.php | File | 25.73 KB | 0644 |
|
PersonalDataErasers.php | File | 622 B | 0644 |
|
PersonalDataExporters.php | File | 2.64 KB | 0644 |
|
PluginActivatedHook.php | File | 682 B | 0644 |
|
Populator.php | File | 29.67 KB | 0644 |
|
PrivacyPolicy.php | File | 3.37 KB | 0644 |
|
Renderer.php | File | 3.95 KB | 0644 |
|
RendererFactory.php | File | 474 B | 0644 |
|
RequirementsChecker.php | File | 4.3 KB | 0644 |
|
Router.php | File | 846 B | 0644 |
|
ServicesChecker.php | File | 4.93 KB | 0644 |
|
Shortcodes.php | File | 6.22 KB | 0644 |
|
Updater.php | File | 1.71 KB | 0644 |
|
index.php | File | 0 B | 0644 |
|