PopulatorData
2 months ago
AccessControl.php
2 years ago
Activator.php
2 months ago
AssetsLoader.php
2 weeks ago
Capabilities.php
2 months ago
Changelog.php
2 months ago
DeactivationPoll.php
3 years ago
DeferredAdminNotices.php
2 months ago
Env.php
6 months ago
Hooks.php
4 weeks ago
HooksWooCommerce.php
1 month ago
Initializer.php
4 weeks ago
Installer.php
10 months ago
Localizer.php
3 years ago
Menu.php
1 month ago
PersonalDataErasers.php
1 month ago
PersonalDataExporters.php
1 month ago
PluginActivatedHook.php
3 years ago
Populator.php
2 weeks ago
PrivacyPolicy.php
1 month ago
Renderer.php
1 year ago
RendererFactory.php
3 years ago
RequirementsChecker.php
2 months ago
Router.php
2 months ago
ServicesChecker.php
3 years ago
Shortcodes.php
1 month ago
SilentUpgraderSkin.php
3 years ago
SubscriberChangesNotifier.php
2 months ago
TranslationUpdater.php
3 months ago
TwigEnvironment.php
1 year ago
TwigFileSystemCache.php
3 years ago
Updater.php
4 days ago
index.php
3 years ago
Changelog.php
179 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Config; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Settings\SettingsController; |
| 9 | use MailPoet\Settings\TrackingConfig; |
| 10 | use MailPoet\Util\Url; |
| 11 | use MailPoet\WooCommerce\Helper; |
| 12 | use MailPoet\WP\Functions as WPFunctions; |
| 13 | |
| 14 | class Changelog { |
| 15 | /** @var WPFunctions */ |
| 16 | private $wp; |
| 17 | |
| 18 | /** @var SettingsController */ |
| 19 | private $settings; |
| 20 | |
| 21 | /** @var Helper */ |
| 22 | private $wooCommerceHelper; |
| 23 | |
| 24 | /** @var Url */ |
| 25 | private $urlHelper; |
| 26 | |
| 27 | /** @var TrackingConfig */ |
| 28 | private $trackingConfig; |
| 29 | |
| 30 | public function __construct( |
| 31 | SettingsController $settings, |
| 32 | WPFunctions $wp, |
| 33 | Helper $wooCommerceHelper, |
| 34 | Url $urlHelper, |
| 35 | TrackingConfig $trackingConfig |
| 36 | ) { |
| 37 | $this->wooCommerceHelper = $wooCommerceHelper; |
| 38 | $this->settings = $settings; |
| 39 | $this->wp = $wp; |
| 40 | $this->urlHelper = $urlHelper; |
| 41 | $this->trackingConfig = $trackingConfig; |
| 42 | } |
| 43 | |
| 44 | public function init() { |
| 45 | // don't run any check when it's an ajax request |
| 46 | if (wp_doing_ajax()) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | // don't run any check when we're not on our pages |
| 51 | $page = $this->getPageSlug(); |
| 52 | if ($page === '' || strpos($page, 'mailpoet') !== 0) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | WPFunctions::get()->addAction( |
| 57 | 'admin_init', |
| 58 | [$this, 'check'] |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | private function getPageSlug(): string { |
| 63 | if (!isset($_GET['page']) || !is_string($_GET['page'])) { |
| 64 | return ''; |
| 65 | } |
| 66 | return sanitize_text_field(wp_unslash($_GET['page'])); |
| 67 | } |
| 68 | |
| 69 | public function check() { |
| 70 | $version = $this->settings->get('version'); |
| 71 | if ($version === null) { |
| 72 | $this->setupNewInstallation(); |
| 73 | $this->maybeRedirectToLandingPage(); |
| 74 | } |
| 75 | $this->checkWooCommerceListImportPage(); |
| 76 | $this->checkRevenueTrackingPermissionPage(); |
| 77 | } |
| 78 | |
| 79 | public function shouldShowWelcomeWizard() { |
| 80 | if ($this->wp->applyFilters('mailpoet_skip_welcome_wizard', false)) { |
| 81 | return false; |
| 82 | } |
| 83 | return $this->settings->get('version') === null; |
| 84 | } |
| 85 | |
| 86 | public function shouldShowLandingPage(): bool { |
| 87 | return $this->shouldShowWelcomeWizard(); |
| 88 | } |
| 89 | |
| 90 | public function shouldShowWooCommerceListImportPage() { |
| 91 | if ($this->wp->applyFilters('mailpoet_skip_woocommerce_import_page', false)) { |
| 92 | return false; |
| 93 | } |
| 94 | return !$this->settings->get('woocommerce_import_screen_displayed') |
| 95 | && $this->wooCommerceHelper->isWooCommerceActive() |
| 96 | && $this->wooCommerceHelper->getOrdersCountCreatedBefore($this->settings->get('installed_at')) > 0 |
| 97 | && $this->wp->currentUserCan('administrator'); |
| 98 | } |
| 99 | |
| 100 | public function shouldShowRevenueTrackingPermissionPage() { |
| 101 | return ($this->settings->get('woocommerce.accept_cookie_revenue_tracking.set') === null) |
| 102 | && $this->trackingConfig->isEmailTrackingEnabled() |
| 103 | && $this->wooCommerceHelper->isWooCommerceActive() |
| 104 | && $this->wp->currentUserCan('administrator'); |
| 105 | } |
| 106 | |
| 107 | public function redirectToLandingPage() { |
| 108 | if (isset($_GET['activate-multi'])) return; // do not redirect when activated with bulk activation mode |
| 109 | |
| 110 | if ($this->shouldShowLandingPage() && !$this->isLandingPage()) { |
| 111 | $this->urlHelper->redirectTo( |
| 112 | $this->wp->adminUrl('admin.php?page=mailpoet-landingpage') |
| 113 | ); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | public function maybeRedirectToLandingPage() { |
| 118 | if ($this->isWelcomeWizardPage()) return; // do not redirect when on welcome wizard page |
| 119 | |
| 120 | if ($this->isExperimentalPage()) return; // do not redirect when on experimental page |
| 121 | |
| 122 | $this->redirectToLandingPage(); |
| 123 | } |
| 124 | |
| 125 | private function setupNewInstallation() { |
| 126 | $this->settings->set('show_congratulate_after_first_newsletter', true); |
| 127 | } |
| 128 | |
| 129 | private function isWelcomeWizardPage() { |
| 130 | return $this->getPageSlug() === Menu::WELCOME_WIZARD_PAGE_SLUG; |
| 131 | } |
| 132 | |
| 133 | private function isLandingPage() { |
| 134 | return $this->getPageSlug() === Menu::LANDINGPAGE_PAGE_SLUG; |
| 135 | } |
| 136 | |
| 137 | private function isExperimentalPage() { |
| 138 | return $this->getPageSlug() === Menu::EXPERIMENTS_PAGE_SLUG; |
| 139 | } |
| 140 | |
| 141 | private function checkWooCommerceListImportPage() { |
| 142 | $page = $this->getPageSlug(); |
| 143 | if ( |
| 144 | $page === '' || |
| 145 | !in_array( |
| 146 | $page, |
| 147 | [ |
| 148 | 'mailpoet-woocommerce-setup', |
| 149 | 'mailpoet-welcome-wizard', |
| 150 | 'mailpoet-migration', |
| 151 | 'mailpoet-landingpage', |
| 152 | ] |
| 153 | ) |
| 154 | && $this->shouldShowWooCommerceListImportPage() |
| 155 | ) { |
| 156 | $this->urlHelper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-setup')); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | private function checkRevenueTrackingPermissionPage() { |
| 161 | $page = $this->getPageSlug(); |
| 162 | if ( |
| 163 | $page === '' || |
| 164 | !in_array( |
| 165 | $page, |
| 166 | [ |
| 167 | 'mailpoet-woocommerce-setup', |
| 168 | 'mailpoet-welcome-wizard', |
| 169 | 'mailpoet-migration', |
| 170 | 'mailpoet-landingpage', |
| 171 | ] |
| 172 | ) |
| 173 | && $this->shouldShowRevenueTrackingPermissionPage() |
| 174 | ) { |
| 175 | $this->urlHelper->redirectTo($this->wp->adminUrl('admin.php?page=mailpoet-woocommerce-setup')); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 |