<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing namespace MailPoet\Config; if (!defined('ABSPATH')) exit; use MailPoet\Settings\SettingsController; use MailPoet\Settings\TrackingConfig; 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 TrackingConfig */ private $trackingConfig; public function __construct( SettingsController $settings, WPFunctions $wp, Helper $wooCommerceHelper, Url $urlHelper, TrackingConfig $trackingConfig ) { $this->wooCommerceHelper = $wooCommerceHelper; $this->settings = $settings; $this->wp = $wp; $this->urlHelper = $urlHelper; $this->trackingConfig = $trackingConfig; } 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( sanitize_text_field(wp_unslash($_GET['page'])), 'mailpoet' ) !== 0) ) { return; } WPFunctions::get()->addAction( 'admin_init', [$this, 'check'] ); } public function check() { $version = $this->settings->get('version'); if ($version === null) { $this->setupNewInstallation(); $this->maybeRedirectToLandingPage(); } $this->checkWooCommerceListImportPage(); $this->checkRevenueTrackingPermissionPage(); } public function shouldShowWelcomeWizard() { if ($this->wp->applyFilters('mailpoet_skip_welcome_wizard', false)) { return false; } return $this->settings->get('version') === null; } public function shouldShowLandingPage(): bool { return $this->shouldShowWelcomeWizard(); } public function shouldShowWooCommerceListImportPage() { if ($this->wp->applyFilters('mailpoet_skip_woocommerce_import_page', false)) { return false; } return !$this->settings->get('woocommerce_import_screen_displayed') && $this->wooCommerceHelper->isWooCommerceActive() && $this->wooCommerceHelper->getOrdersCountCreatedBefore($this->settings->get('installed_at')) > 0 && $this->wp->currentUserCan('administrator'); } public function shouldShowRevenueTrackingPermissionPage() { return ($this->settings->get('woocommerce.accept_cookie_revenue_tracking.set') === null) && $this->trackingConfig->isEmailTrackingEnabled() && $this->wooCommerceHelper->isWooCommerceActive() && $this->wp->currentUserCan('administrator'); } public function redirectToLandingPage() { if (isset($_GET['activate-multi'])) return; // do not redirect when activated with bulk activation mode if ($this->shouldShowLandingPage() && !$this->isLandingPage()) { $this->urlHelper->redirectTo( $this->wp->adminUrl('admin.php?page=mailpoet-landingpage') ); } } public function maybeRedirectToLandingPage() { if ($this->isWelcomeWizardPage()) return; // do not redirect when on welcome wizard page if ($this->isExperimentalPage()) return; // do not redirect when on experimental page $this->redirectToLandingPage(); } private function setupNewInstallation() { $this->settings->set('show_congratulate_after_first_newsletter', true); } private function isWelcomeWizardPage() { return isset($_GET['page']) && sanitize_text_field(wp_unslash($_GET['page'])) === Menu::WELCOME_WIZARD_PAGE_SLUG; } private function isLandingPage() { return isset($_GET['page']) && sanitize_text_field(wp_unslash($_GET['page'])) === Menu::LANDINGPAGE_PAGE_SLUG; } private function isExperimentalPage() { return isset($_GET['page']) && sanitize_text_field(wp_unslash($_GET['page'])) === Menu::EXPERIMENTS_PAGE_SLUG; } private function checkWooCommerceListImportPage() { if ( !isset($_GET['page']) || !in_array( sanitize_text_field(wp_unslash($_GET['page'])), [ 'mailpoet-woocommerce-setup', 'mailpoet-welcome-wizard', 'mailpoet-migration', 'mailpoet-landingpage', ] ) && $this->shouldShowWooCommerceListImportPage() ) { $this->urlHelper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-setup')); } } private function checkRevenueTrackingPermissionPage() { if ( !isset($_GET['page']) || !in_array( sanitize_text_field(wp_unslash($_GET['page'])), [ 'mailpoet-woocommerce-setup', 'mailpoet-welcome-wizard', 'mailpoet-migration', 'mailpoet-landingpage', ] ) && $this->shouldShowRevenueTrackingPermissionPage() ) { $this->urlHelper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-setup')); } } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
PopulatorData | Folder | 0755 |
|
|
AccessControl.php | File | 3.89 KB | 0644 |
|
Activator.php | File | 4.94 KB | 0644 |
|
AssetsLoader.php | File | 1.68 KB | 0644 |
|
Capabilities.php | File | 2.87 KB | 0644 |
|
Changelog.php | File | 5.04 KB | 0644 |
|
DeactivationPoll.php | File | 1.43 KB | 0644 |
|
DeferredAdminNotices.php | File | 1.16 KB | 0644 |
|
Env.php | File | 4.16 KB | 0644 |
|
Hooks.php | File | 20.06 KB | 0644 |
|
HooksWooCommerce.php | File | 6.76 KB | 0644 |
|
Initializer.php | File | 16.58 KB | 0644 |
|
Installer.php | File | 3.12 KB | 0644 |
|
Localizer.php | File | 2.49 KB | 0644 |
|
Menu.php | File | 23.54 KB | 0644 |
|
PersonalDataErasers.php | File | 769 B | 0644 |
|
PersonalDataExporters.php | File | 3.22 KB | 0644 |
|
PluginActivatedHook.php | File | 776 B | 0644 |
|
Populator.php | File | 23.37 KB | 0644 |
|
PrivacyPolicy.php | File | 4.53 KB | 0644 |
|
Renderer.php | File | 4.34 KB | 0644 |
|
RendererFactory.php | File | 670 B | 0644 |
|
RequirementsChecker.php | File | 3.73 KB | 0644 |
|
Router.php | File | 1006 B | 0644 |
|
ServicesChecker.php | File | 7.04 KB | 0644 |
|
Shortcodes.php | File | 8.63 KB | 0644 |
|
SilentUpgraderSkin.php | File | 570 B | 0644 |
|
SubscriberChangesNotifier.php | File | 5 KB | 0644 |
|
TranslationUpdater.php | File | 7.92 KB | 0644 |
|
TwigEnvironment.php | File | 694 B | 0644 |
|
TwigFileSystemCache.php | File | 853 B | 0644 |
|
Updater.php | File | 1.97 KB | 0644 |
|
index.php | File | 6 B | 0644 |
|